@atlaskit/editor-synced-block-provider 4.1.0 → 4.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.
@@ -3,22 +3,18 @@ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
3
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
4
4
  import _createClass from "@babel/runtime/helpers/createClass";
5
5
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
6
- 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
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
8
- import _regeneratorRuntime from "@babel/runtime/regenerator";
9
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; } } }; }
10
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; } }
11
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; }
9
+ 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; }
10
+ 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; }
11
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
12
12
  import isEqual from 'lodash/isEqual';
13
- import rafSchedule from 'raf-schd';
14
13
  import { logException } from '@atlaskit/editor-common/monitoring';
15
- import { ProviderFactory } from '@atlaskit/editor-common/provider-factory';
16
- import { fg } from '@atlaskit/platform-feature-flags';
17
14
  import { SyncBlockError } from '../common/types';
18
15
  import { fetchErrorPayload, fetchSuccessPayload, getSourceInfoErrorPayload, updateReferenceErrorPayload } from '../utils/errorHandling';
19
16
  import { getFetchExperience, getFetchSourceInfoExperience, getSaveReferenceExperience } from '../utils/experienceTracking';
20
17
  import { resolveSyncBlockInstance } from '../utils/resolveSyncBlockInstance';
21
- import { parseResourceId } from '../utils/resourceId';
22
18
  import { createSyncBlockNode } from '../utils/utils';
23
19
  import { SyncBlockBatchFetcher } from './syncBlockBatchFetcher';
24
20
  import { syncBlockInMemorySessionCache } from './syncBlockInMemorySessionCache';
@@ -32,6 +28,8 @@ var CACHE_KEY_PREFIX = 'sync-block-data-';
32
28
  // Handles fetching source URL and title for sync blocks.
33
29
  // Can be used in both editor and renderer contexts.
34
30
  export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
31
+ // Track the setTimeout handle for queued flush so we can cancel it on destroy
32
+
35
33
  function ReferenceSyncBlockStoreManager(dataProvider) {
36
34
  var _this = this,
37
35
  _this$dataProvider;
@@ -40,91 +38,64 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
40
38
  // This starts as true to always flush the cache when document is saved for the first time
41
39
  // to cater the case when a editor session is closed without document being updated right after reference block is deleted
42
40
  _defineProperty(this, "isCacheDirty", true);
43
- _defineProperty(this, "isRefreshingSubscriptions", false);
44
- // Flag to indicate if real-time subscriptions are enabled
45
- _defineProperty(this, "useRealTimeSubscriptions", false);
46
41
  // Keep track of the last flushed subscriptions to optimize cache flushing on document save
47
42
  _defineProperty(this, "lastFlushedSyncedBlocks", {});
48
43
  // Track if a flush operation is currently in progress
49
44
  _defineProperty(this, "isFlushInProgress", false);
50
45
  // Track if another flush is needed after the current one completes
51
46
  _defineProperty(this, "flushNeededAfterCurrent", false);
52
- _defineProperty(this, "pendingFetchRequests", new Set());
53
- _defineProperty(this, "scheduledBatchFetch", rafSchedule(function () {
54
- if (_this.pendingFetchRequests.size === 0) {
55
- return;
56
- }
57
- var resourceIds = Array.from(_this.pendingFetchRequests);
58
- var syncBlockNodes = resourceIds.map(function (resId) {
59
- var subscriptions = _this.subscriptions.get(resId) || {};
60
- var firstLocalId = Object.keys(subscriptions)[0] || '';
61
- return createSyncBlockNode(firstLocalId, resId);
62
- });
63
- _this.pendingFetchRequests.clear();
64
- _this.fetchSyncBlocksData(syncBlockNodes).catch(function (error) {
65
- logException(error, {
66
- location: 'editor-synced-block-provider/referenceSyncBlockStoreManager/batchedFetchSyncBlocks'
67
- });
68
- resourceIds.forEach(function (resId) {
69
- var _this$fireAnalyticsEv;
70
- (_this$fireAnalyticsEv = _this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv === void 0 || _this$fireAnalyticsEv.call(_this, fetchErrorPayload(error.message, resId));
71
- });
72
- });
73
- }));
74
- this.subscriptions = new Map();
75
- this.titleSubscriptions = new Map();
76
47
  this.dataProvider = dataProvider;
77
48
  this.syncBlockFetchDataRequests = new Map();
78
49
  this.syncBlockSourceInfoRequests = new Map();
79
- this.providerFactories = new Map();
80
- this.pendingCacheDeletions = new Map();
81
- this.graphqlSubscriptions = new Map();
82
- this.subscriptionChangeListeners = new Set();
83
50
  this.newlyAddedSyncBlocks = new Set();
84
- if (fg('platform_synced_block_patch_5')) {
85
- this._subscriptionManager = new SyncBlockSubscriptionManager({
86
- getDataProvider: function getDataProvider() {
87
- return _this.dataProvider;
88
- },
89
- getSubscriptions: function getSubscriptions() {
90
- return _this.subscriptions;
91
- },
92
- getFromCache: function getFromCache(rid) {
93
- return _this.getFromCache(rid);
94
- },
95
- updateCache: function updateCache(inst) {
96
- return _this.updateCache(inst);
97
- },
98
- fetchSyncBlockSourceInfo: function fetchSyncBlockSourceInfo(rid) {
99
- return _this.fetchSyncBlockSourceInfo(rid);
100
- },
101
- getFireAnalyticsEvent: function getFireAnalyticsEvent() {
102
- return _this.fireAnalyticsEvent;
103
- }
104
- });
105
- this._providerFactoryManager = new SyncBlockProviderFactoryManager({
106
- getDataProvider: function getDataProvider() {
107
- return _this.dataProvider;
108
- },
109
- getFromCache: function getFromCache(rid) {
110
- return _this.getFromCache(rid);
111
- },
112
- getFireAnalyticsEvent: function getFireAnalyticsEvent() {
113
- return _this.fireAnalyticsEvent;
114
- }
115
- });
116
- this._batchFetcher = new SyncBlockBatchFetcher({
117
- getSubscriptions: function getSubscriptions() {
118
- return _this.subscriptions;
119
- },
120
- fetchSyncBlocksData: function fetchSyncBlocksData(nodes) {
121
- return _this.fetchSyncBlocksData(nodes);
122
- },
123
- getFireAnalyticsEvent: function getFireAnalyticsEvent() {
124
- return _this.fireAnalyticsEvent;
125
- }
126
- });
127
- }
51
+ this._subscriptionManager = new SyncBlockSubscriptionManager({
52
+ getDataProvider: function getDataProvider() {
53
+ return _this.dataProvider;
54
+ },
55
+ getFromCache: function getFromCache(rid) {
56
+ return _this.getFromCache(rid);
57
+ },
58
+ updateCache: function updateCache(inst) {
59
+ return _this.updateCache(inst);
60
+ },
61
+ deleteFromCache: function deleteFromCache(rid) {
62
+ return _this.deleteFromCache(rid);
63
+ },
64
+ debouncedBatchedFetchSyncBlocks: function debouncedBatchedFetchSyncBlocks(rid) {
65
+ return _this.debouncedBatchedFetchSyncBlocks(rid);
66
+ },
67
+ fetchSyncBlockSourceInfo: function fetchSyncBlockSourceInfo(rid) {
68
+ return _this.fetchSyncBlockSourceInfo(rid);
69
+ },
70
+ getFireAnalyticsEvent: function getFireAnalyticsEvent() {
71
+ return _this.fireAnalyticsEvent;
72
+ },
73
+ markCacheDirty: function markCacheDirty() {
74
+ _this.isCacheDirty = true;
75
+ }
76
+ });
77
+ this._providerFactoryManager = new SyncBlockProviderFactoryManager({
78
+ getDataProvider: function getDataProvider() {
79
+ return _this.dataProvider;
80
+ },
81
+ getFromCache: function getFromCache(rid) {
82
+ return _this.getFromCache(rid);
83
+ },
84
+ getFireAnalyticsEvent: function getFireAnalyticsEvent() {
85
+ return _this.fireAnalyticsEvent;
86
+ }
87
+ });
88
+ this._batchFetcher = new SyncBlockBatchFetcher({
89
+ getSubscriptions: function getSubscriptions() {
90
+ return _this._subscriptionManager.getSubscriptions();
91
+ },
92
+ fetchSyncBlocksData: function fetchSyncBlocksData(nodes) {
93
+ return _this.fetchSyncBlocksData(nodes);
94
+ },
95
+ getFireAnalyticsEvent: function getFireAnalyticsEvent() {
96
+ return _this.fireAnalyticsEvent;
97
+ }
98
+ });
128
99
 
129
100
  // The provider might have SSR data cache already set, so we need to update the cache in session memory storage
130
101
  this.setSSRDataInSessionCache((_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.getNodeDataCacheKeys());
@@ -139,21 +110,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
139
110
  return _createClass(ReferenceSyncBlockStoreManager, [{
140
111
  key: "setRealTimeSubscriptionsEnabled",
141
112
  value: function setRealTimeSubscriptionsEnabled(enabled) {
142
- if (this._subscriptionManager && fg('platform_synced_block_patch_5')) {
143
- this._subscriptionManager.setRealTimeSubscriptionsEnabled(enabled);
144
- return;
145
- }
146
- if (this.useRealTimeSubscriptions === enabled) {
147
- return;
148
- }
149
- this.useRealTimeSubscriptions = enabled;
150
- if (enabled) {
151
- // Set up subscriptions for all currently subscribed blocks
152
- this.setupGraphQLSubscriptionsForAllBlocks();
153
- } else {
154
- // Clean up all GraphQL subscriptions
155
- this.cleanupAllGraphQLSubscriptions();
156
- }
113
+ this._subscriptionManager.setRealTimeSubscriptionsEnabled(enabled);
157
114
  }
158
115
 
159
116
  /**
@@ -162,10 +119,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
162
119
  }, {
163
120
  key: "isRealTimeSubscriptionsEnabled",
164
121
  value: function isRealTimeSubscriptionsEnabled() {
165
- if (this._subscriptionManager && fg('platform_synced_block_patch_5')) {
166
- return this._subscriptionManager.isRealTimeSubscriptionsEnabled();
167
- }
168
- return this.useRealTimeSubscriptions;
122
+ return this._subscriptionManager.isRealTimeSubscriptionsEnabled();
169
123
  }
170
124
 
171
125
  /**
@@ -175,10 +129,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
175
129
  }, {
176
130
  key: "getSubscribedResourceIds",
177
131
  value: function getSubscribedResourceIds() {
178
- if (this._subscriptionManager && fg('platform_synced_block_patch_5')) {
179
- return this._subscriptionManager.getSubscribedResourceIds();
180
- }
181
- return Array.from(this.subscriptions.keys());
132
+ return this._subscriptionManager.getSubscribedResourceIds();
182
133
  }
183
134
 
184
135
  /**
@@ -189,38 +140,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
189
140
  }, {
190
141
  key: "onSubscriptionsChanged",
191
142
  value: function onSubscriptionsChanged(listener) {
192
- var _this2 = this;
193
- if (this._subscriptionManager && fg('platform_synced_block_patch_5')) {
194
- return this._subscriptionManager.onSubscriptionsChanged(listener);
195
- }
196
- this.subscriptionChangeListeners.add(listener);
197
- return function () {
198
- _this2.subscriptionChangeListeners.delete(listener);
199
- };
200
- }
201
-
202
- /**
203
- * Notifies all subscription change listeners.
204
- */
205
- }, {
206
- key: "notifySubscriptionChangeListeners",
207
- value: function notifySubscriptionChangeListeners() {
208
- var _this3 = this;
209
- if (this._subscriptionManager && fg('platform_synced_block_patch_5')) {
210
- this._subscriptionManager.notifySubscriptionChangeListeners();
211
- return;
212
- }
213
- this.subscriptionChangeListeners.forEach(function (listener) {
214
- try {
215
- listener();
216
- } catch (error) {
217
- var _this3$fireAnalyticsE;
218
- logException(error, {
219
- location: 'editor-synced-block-provider/referenceSyncBlockStoreManager/notifySubscriptionChangeListeners'
220
- });
221
- (_this3$fireAnalyticsE = _this3.fireAnalyticsEvent) === null || _this3$fireAnalyticsE === void 0 || _this3$fireAnalyticsE.call(_this3, fetchErrorPayload(error.message));
222
- }
223
- });
143
+ return this._subscriptionManager.onSubscriptionsChanged(listener);
224
144
  }
225
145
 
226
146
  /**
@@ -231,19 +151,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
231
151
  }, {
232
152
  key: "handleSubscriptionUpdate",
233
153
  value: function handleSubscriptionUpdate(syncBlockInstance) {
234
- if (this._subscriptionManager && fg('platform_synced_block_patch_5')) {
235
- this._subscriptionManager.handleSubscriptionUpdate(syncBlockInstance);
236
- return;
237
- }
238
- if (!syncBlockInstance.resourceId) {
239
- return;
240
- }
241
- var existingSyncBlock = this.getFromCache(syncBlockInstance.resourceId);
242
- var resolvedSyncBlockInstance = existingSyncBlock ? resolveSyncBlockInstance(existingSyncBlock, syncBlockInstance) : syncBlockInstance;
243
- this.updateCache(resolvedSyncBlockInstance);
244
- if (!syncBlockInstance.error) {
245
- this.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
246
- }
154
+ this._subscriptionManager.handleSubscriptionUpdate(syncBlockInstance);
247
155
  }
248
156
  }, {
249
157
  key: "setFireAnalyticsEvent",
@@ -317,233 +225,6 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
317
225
  return undefined;
318
226
  }
319
227
  }
320
-
321
- /**
322
- * Refreshes the subscriptions for all sync blocks.
323
- * This is a fallback polling mechanism when real-time subscriptions are not enabled.
324
- * @returns {Promise<void>}
325
- */
326
- }, {
327
- key: "refreshSubscriptions",
328
- value: (function () {
329
- var _refreshSubscriptions = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
330
- var syncBlocks, _iterator, _step, _loop, _this$fireAnalyticsEv2;
331
- return _regeneratorRuntime.wrap(function _callee$(_context2) {
332
- while (1) switch (_context2.prev = _context2.next) {
333
- case 0:
334
- if (!this.useRealTimeSubscriptions) {
335
- _context2.next = 2;
336
- break;
337
- }
338
- return _context2.abrupt("return");
339
- case 2:
340
- if (!this.isRefreshingSubscriptions) {
341
- _context2.next = 4;
342
- break;
343
- }
344
- return _context2.abrupt("return");
345
- case 4:
346
- this.isRefreshingSubscriptions = true;
347
- syncBlocks = [];
348
- _iterator = _createForOfIteratorHelper(this.subscriptions.entries());
349
- _context2.prev = 7;
350
- _loop = /*#__PURE__*/_regeneratorRuntime.mark(function _loop() {
351
- var _step$value, resourceId, callbacks;
352
- return _regeneratorRuntime.wrap(function _loop$(_context) {
353
- while (1) switch (_context.prev = _context.next) {
354
- case 0:
355
- _step$value = _slicedToArray(_step.value, 2), resourceId = _step$value[0], callbacks = _step$value[1];
356
- Object.keys(callbacks).forEach(function (localId) {
357
- syncBlocks.push(createSyncBlockNode(localId, resourceId));
358
- });
359
- case 2:
360
- case "end":
361
- return _context.stop();
362
- }
363
- }, _loop);
364
- });
365
- _iterator.s();
366
- case 10:
367
- if ((_step = _iterator.n()).done) {
368
- _context2.next = 14;
369
- break;
370
- }
371
- return _context2.delegateYield(_loop(), "t0", 12);
372
- case 12:
373
- _context2.next = 10;
374
- break;
375
- case 14:
376
- _context2.next = 19;
377
- break;
378
- case 16:
379
- _context2.prev = 16;
380
- _context2.t1 = _context2["catch"](7);
381
- _iterator.e(_context2.t1);
382
- case 19:
383
- _context2.prev = 19;
384
- _iterator.f();
385
- return _context2.finish(19);
386
- case 22:
387
- _context2.prev = 22;
388
- _context2.next = 25;
389
- return this.fetchSyncBlocksData(syncBlocks);
390
- case 25:
391
- _context2.next = 31;
392
- break;
393
- case 27:
394
- _context2.prev = 27;
395
- _context2.t2 = _context2["catch"](22);
396
- logException(_context2.t2, {
397
- location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
398
- });
399
- (_this$fireAnalyticsEv2 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv2 === void 0 || _this$fireAnalyticsEv2.call(this, fetchErrorPayload(_context2.t2.message));
400
- case 31:
401
- _context2.prev = 31;
402
- this.isRefreshingSubscriptions = false;
403
- return _context2.finish(31);
404
- case 34:
405
- case "end":
406
- return _context2.stop();
407
- }
408
- }, _callee, this, [[7, 16, 19, 22], [22, 27, 31, 34]]);
409
- }));
410
- function refreshSubscriptions() {
411
- return _refreshSubscriptions.apply(this, arguments);
412
- }
413
- return refreshSubscriptions;
414
- }()
415
- /**
416
- * Sets up a GraphQL subscription for a specific block.
417
- * @param resourceId - The resource ID of the block to subscribe to
418
- */
419
- )
420
- }, {
421
- key: "setupGraphQLSubscription",
422
- value: function setupGraphQLSubscription(resourceId) {
423
- var _this$dataProvider3,
424
- _this4 = this;
425
- if (this._subscriptionManager && fg('platform_synced_block_patch_5')) {
426
- this._subscriptionManager.setupSubscription(resourceId);
427
- return;
428
- }
429
-
430
- // Don't set up duplicate subscriptions
431
- if (this.graphqlSubscriptions.has(resourceId)) {
432
- return;
433
- }
434
- if (!((_this$dataProvider3 = this.dataProvider) !== null && _this$dataProvider3 !== void 0 && _this$dataProvider3.subscribeToBlockUpdates)) {
435
- return;
436
- }
437
- var unsubscribe = this.dataProvider.subscribeToBlockUpdates(resourceId, function (syncBlockInstance) {
438
- // Handle the subscription update
439
- _this4.handleGraphQLSubscriptionUpdate(syncBlockInstance);
440
- }, function (error) {
441
- var _this4$fireAnalyticsE;
442
- logException(error, {
443
- location: 'editor-synced-block-provider/referenceSyncBlockStoreManager/graphql-subscription'
444
- });
445
- (_this4$fireAnalyticsE = _this4.fireAnalyticsEvent) === null || _this4$fireAnalyticsE === void 0 || _this4$fireAnalyticsE.call(_this4, fetchErrorPayload(error.message));
446
- });
447
- if (unsubscribe) {
448
- this.graphqlSubscriptions.set(resourceId, unsubscribe);
449
- }
450
- }
451
-
452
- /**
453
- * Handles updates received from GraphQL subscriptions.
454
- * @param syncBlockInstance - The updated sync block instance
455
- */
456
- }, {
457
- key: "handleGraphQLSubscriptionUpdate",
458
- value: function handleGraphQLSubscriptionUpdate(syncBlockInstance) {
459
- var _this5 = this;
460
- if (!syncBlockInstance.resourceId) {
461
- return;
462
- }
463
- var existingSyncBlock = this.getFromCache(syncBlockInstance.resourceId);
464
- var resolvedSyncBlockInstance = existingSyncBlock ? resolveSyncBlockInstance(existingSyncBlock, syncBlockInstance) : syncBlockInstance;
465
- this.updateCache(resolvedSyncBlockInstance);
466
- if (!syncBlockInstance.error) {
467
- var callbacks = this.subscriptions.get(syncBlockInstance.resourceId);
468
- var localIds = callbacks ? Object.keys(callbacks) : [];
469
- localIds.forEach(function (localId) {
470
- var _this5$fireAnalyticsE, _syncBlockInstance$da;
471
- (_this5$fireAnalyticsE = _this5.fireAnalyticsEvent) === null || _this5$fireAnalyticsE === void 0 || _this5$fireAnalyticsE.call(_this5, fetchSuccessPayload(syncBlockInstance.resourceId, localId, (_syncBlockInstance$da = syncBlockInstance.data) === null || _syncBlockInstance$da === void 0 ? void 0 : _syncBlockInstance$da.product));
472
- });
473
- this.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
474
- } else {
475
- var _syncBlockInstance$er, _syncBlockInstance$er2, _this$fireAnalyticsEv3;
476
- var errorMessage = ((_syncBlockInstance$er = syncBlockInstance.error) === null || _syncBlockInstance$er === void 0 ? void 0 : _syncBlockInstance$er.reason) || ((_syncBlockInstance$er2 = syncBlockInstance.error) === null || _syncBlockInstance$er2 === void 0 ? void 0 : _syncBlockInstance$er2.type);
477
- (_this$fireAnalyticsEv3 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv3 === void 0 || _this$fireAnalyticsEv3.call(this, fetchErrorPayload(errorMessage, syncBlockInstance.resourceId));
478
- }
479
- }
480
-
481
- /**
482
- * Cleans up the GraphQL subscription for a specific block.
483
- * @param resourceId - The resource ID of the block to unsubscribe from
484
- */
485
- }, {
486
- key: "cleanupGraphQLSubscription",
487
- value: function cleanupGraphQLSubscription(resourceId) {
488
- if (this._subscriptionManager && fg('platform_synced_block_patch_5')) {
489
- this._subscriptionManager.cleanupSubscription(resourceId);
490
- return;
491
- }
492
- var unsubscribe = this.graphqlSubscriptions.get(resourceId);
493
- if (unsubscribe) {
494
- unsubscribe();
495
- this.graphqlSubscriptions.delete(resourceId);
496
- }
497
- }
498
-
499
- /**
500
- * Sets up GraphQL subscriptions for all currently subscribed blocks.
501
- */
502
- }, {
503
- key: "setupGraphQLSubscriptionsForAllBlocks",
504
- value: function setupGraphQLSubscriptionsForAllBlocks() {
505
- if (this._subscriptionManager && fg('platform_synced_block_patch_5')) {
506
- this._subscriptionManager.setupSubscriptionsForAllBlocks();
507
- return;
508
- }
509
- var _iterator2 = _createForOfIteratorHelper(this.subscriptions.keys()),
510
- _step2;
511
- try {
512
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
513
- var resourceId = _step2.value;
514
- this.setupGraphQLSubscription(resourceId);
515
- }
516
- } catch (err) {
517
- _iterator2.e(err);
518
- } finally {
519
- _iterator2.f();
520
- }
521
- }
522
-
523
- /**
524
- * Cleans up all GraphQL subscriptions.
525
- */
526
- }, {
527
- key: "cleanupAllGraphQLSubscriptions",
528
- value: function cleanupAllGraphQLSubscriptions() {
529
- if (this._subscriptionManager && fg('platform_synced_block_patch_5')) {
530
- this._subscriptionManager.cleanupAll();
531
- return;
532
- }
533
- var _iterator3 = _createForOfIteratorHelper(this.graphqlSubscriptions.values()),
534
- _step3;
535
- try {
536
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
537
- var unsubscribe = _step3.value;
538
- unsubscribe();
539
- }
540
- } catch (err) {
541
- _iterator3.e(err);
542
- } finally {
543
- _iterator3.f();
544
- }
545
- this.graphqlSubscriptions.clear();
546
- }
547
228
  }, {
548
229
  key: "fetchSyncBlockSourceInfoBySourceAri",
549
230
  value: function fetchSyncBlockSourceInfoBySourceAri(sourceAri) {
@@ -555,18 +236,18 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
555
236
  var sourceInfo = this.dataProvider.fetchSyncBlockSourceInfo(undefined, sourceAri, undefined, hasAccess);
556
237
  return sourceInfo;
557
238
  } catch (error) {
558
- var _this$fireAnalyticsEv4;
239
+ var _this$fireAnalyticsEv;
559
240
  logException(error, {
560
241
  location: 'editor-synced-block-provider/referenceSyncBlockStoreManager/fetchSyncBlockSourceInfoBySourceAri'
561
242
  });
562
- (_this$fireAnalyticsEv4 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv4 === void 0 || _this$fireAnalyticsEv4.call(this, getSourceInfoErrorPayload(error.message));
243
+ (_this$fireAnalyticsEv = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv === void 0 || _this$fireAnalyticsEv.call(this, getSourceInfoErrorPayload(error.message));
563
244
  return Promise.resolve(undefined);
564
245
  }
565
246
  }
566
247
  }, {
567
248
  key: "fetchSyncBlockSourceInfo",
568
249
  value: function fetchSyncBlockSourceInfo(resourceId) {
569
- var _this6 = this;
250
+ var _this2 = this;
570
251
  try {
571
252
  var _this$fetchSourceInfo;
572
253
  if (!resourceId || !this.dataProvider) {
@@ -600,54 +281,54 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
600
281
  });
601
282
  }
602
283
  if (!sourceAri || !product || !blockInstanceId) {
603
- var _this$fireAnalyticsEv5;
604
- (_this$fireAnalyticsEv5 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv5 === void 0 || _this$fireAnalyticsEv5.call(this, getSourceInfoErrorPayload('SourceAri, product or blockInstanceId missing', resourceId));
284
+ var _this$fireAnalyticsEv2;
285
+ (_this$fireAnalyticsEv2 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv2 === void 0 || _this$fireAnalyticsEv2.call(this, getSourceInfoErrorPayload('SourceAri, product or blockInstanceId missing', resourceId));
605
286
  return Promise.resolve(undefined);
606
287
  }
607
288
  (_this$fetchSourceInfo = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo === void 0 || _this$fetchSourceInfo.start({});
608
289
  var sourceInfoPromise = this.dataProvider.fetchSyncBlockSourceInfo(blockInstanceId, sourceAri, product, true // hasAccess
609
290
  ).then(function (sourceInfo) {
610
291
  if (!sourceInfo) {
611
- var _this6$fetchSourceInf, _this6$fireAnalyticsE;
612
- (_this6$fetchSourceInf = _this6.fetchSourceInfoExperience) === null || _this6$fetchSourceInf === void 0 || _this6$fetchSourceInf.failure({
292
+ var _this2$fetchSourceInf, _this2$fireAnalyticsE;
293
+ (_this2$fetchSourceInf = _this2.fetchSourceInfoExperience) === null || _this2$fetchSourceInf === void 0 || _this2$fetchSourceInf.failure({
613
294
  reason: 'No source info returned'
614
295
  });
615
- (_this6$fireAnalyticsE = _this6.fireAnalyticsEvent) === null || _this6$fireAnalyticsE === void 0 || _this6$fireAnalyticsE.call(_this6, getSourceInfoErrorPayload('No source info returned', resourceId));
296
+ (_this2$fireAnalyticsE = _this2.fireAnalyticsEvent) === null || _this2$fireAnalyticsE === void 0 || _this2$fireAnalyticsE.call(_this2, getSourceInfoErrorPayload('No source info returned', resourceId));
616
297
  return undefined;
617
298
  }
618
- _this6.updateCacheWithSourceInfo(resourceId, sourceInfo);
299
+ _this2.updateCacheWithSourceInfo(resourceId, sourceInfo);
619
300
  if (sourceInfo.title) {
620
- _this6.updateSourceTitleSubscriptions(resourceId, sourceInfo.title);
301
+ _this2._subscriptionManager.updateSourceTitleSubscriptions(resourceId, sourceInfo.title);
621
302
  }
622
303
  if (sourceInfo.title && sourceInfo.url) {
623
- var _this6$fetchSourceInf2;
624
- (_this6$fetchSourceInf2 = _this6.fetchSourceInfoExperience) === null || _this6$fetchSourceInf2 === void 0 || _this6$fetchSourceInf2.success();
304
+ var _this2$fetchSourceInf2;
305
+ (_this2$fetchSourceInf2 = _this2.fetchSourceInfoExperience) === null || _this2$fetchSourceInf2 === void 0 || _this2$fetchSourceInf2.success();
625
306
  } else {
626
- var _this6$fetchSourceInf3, _this6$fireAnalyticsE2;
627
- (_this6$fetchSourceInf3 = _this6.fetchSourceInfoExperience) === null || _this6$fetchSourceInf3 === void 0 || _this6$fetchSourceInf3.failure({
307
+ var _this2$fetchSourceInf3, _this2$fireAnalyticsE2;
308
+ (_this2$fetchSourceInf3 = _this2.fetchSourceInfoExperience) === null || _this2$fetchSourceInf3 === void 0 || _this2$fetchSourceInf3.failure({
628
309
  reason: 'Missing title or url'
629
310
  });
630
- (_this6$fireAnalyticsE2 = _this6.fireAnalyticsEvent) === null || _this6$fireAnalyticsE2 === void 0 || _this6$fireAnalyticsE2.call(_this6, getSourceInfoErrorPayload('Missing title or url', resourceId));
311
+ (_this2$fireAnalyticsE2 = _this2.fireAnalyticsEvent) === null || _this2$fireAnalyticsE2 === void 0 || _this2$fireAnalyticsE2.call(_this2, getSourceInfoErrorPayload('Missing title or url', resourceId));
631
312
  }
632
313
  return sourceInfo;
633
314
  }).catch(function (error) {
634
- var _this6$fetchSourceInf4, _this6$fireAnalyticsE3;
635
- (_this6$fetchSourceInf4 = _this6.fetchSourceInfoExperience) === null || _this6$fetchSourceInf4 === void 0 || _this6$fetchSourceInf4.failure({
315
+ var _this2$fetchSourceInf4, _this2$fireAnalyticsE3;
316
+ (_this2$fetchSourceInf4 = _this2.fetchSourceInfoExperience) === null || _this2$fetchSourceInf4 === void 0 || _this2$fetchSourceInf4.failure({
636
317
  reason: error.message
637
318
  });
638
- (_this6$fireAnalyticsE3 = _this6.fireAnalyticsEvent) === null || _this6$fireAnalyticsE3 === void 0 || _this6$fireAnalyticsE3.call(_this6, getSourceInfoErrorPayload(error.message, resourceId));
319
+ (_this2$fireAnalyticsE3 = _this2.fireAnalyticsEvent) === null || _this2$fireAnalyticsE3 === void 0 || _this2$fireAnalyticsE3.call(_this2, getSourceInfoErrorPayload(error.message, resourceId));
639
320
  return undefined;
640
321
  }).finally(function () {
641
- _this6.syncBlockSourceInfoRequests.delete(resourceId);
322
+ _this2.syncBlockSourceInfoRequests.delete(resourceId);
642
323
  });
643
324
  this.syncBlockSourceInfoRequests.set(resourceId, sourceInfoPromise);
644
325
  return sourceInfoPromise;
645
326
  } catch (error) {
646
- var _this$fireAnalyticsEv6;
327
+ var _this$fireAnalyticsEv3;
647
328
  logException(error, {
648
329
  location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
649
330
  });
650
- (_this$fireAnalyticsEv6 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv6 === void 0 || _this$fireAnalyticsEv6.call(this, getSourceInfoErrorPayload(error.message, resourceId));
331
+ (_this$fireAnalyticsEv3 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv3 === void 0 || _this$fireAnalyticsEv3.call(this, getSourceInfoErrorPayload(error.message, resourceId));
651
332
  }
652
333
  return Promise.resolve(undefined);
653
334
  }
@@ -660,31 +341,31 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
660
341
  }, {
661
342
  key: "processPrefetchedData",
662
343
  value: (function () {
663
- var _processPrefetchedData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(prefetchedData) {
344
+ var _processPrefetchedData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(prefetchedData) {
664
345
  var _this$fetchExperience,
665
- _this7 = this;
346
+ _this3 = this;
666
347
  var prefetchedResolvedData, _this$processFetchedD, hasUnexpectedError, hasExpectedError, _this$fetchExperience2, _this$fetchExperience3, _this$fetchExperience4, _this$fetchExperience5;
667
- return _regeneratorRuntime.wrap(function _callee2$(_context3) {
668
- while (1) switch (_context3.prev = _context3.next) {
348
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
349
+ while (1) switch (_context.prev = _context.next) {
669
350
  case 0:
670
351
  if (prefetchedData) {
671
- _context3.next = 2;
352
+ _context.next = 2;
672
353
  break;
673
354
  }
674
- return _context3.abrupt("return");
355
+ return _context.abrupt("return");
675
356
  case 2:
676
357
  // start the fetch experience (this should be started much earlier to properly track performance, but better late than never)
677
358
  (_this$fetchExperience = this.fetchExperience) === null || _this$fetchExperience === void 0 || _this$fetchExperience.start({});
678
359
 
679
360
  // mark the sync block requests as in fly
680
361
  prefetchedData.resourceIds.forEach(function (resourceId) {
681
- _this7.syncBlockFetchDataRequests.set(resourceId, true);
362
+ _this3.syncBlockFetchDataRequests.set(resourceId, true);
682
363
  });
683
- _context3.prev = 4;
684
- _context3.next = 7;
364
+ _context.prev = 4;
365
+ _context.next = 7;
685
366
  return prefetchedData.prefetchPromise;
686
367
  case 7:
687
- prefetchedResolvedData = _context3.sent;
368
+ prefetchedResolvedData = _context.sent;
688
369
  _this$processFetchedD = this.processFetchedData(prefetchedResolvedData), hasUnexpectedError = _this$processFetchedD.hasUnexpectedError, hasExpectedError = _this$processFetchedD.hasExpectedError;
689
370
  if (hasUnexpectedError) {
690
371
  (_this$fetchExperience2 = this.fetchExperience) === null || _this$fetchExperience2 === void 0 || _this$fetchExperience2.failure({
@@ -697,26 +378,26 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
697
378
  } else {
698
379
  (_this$fetchExperience4 = this.fetchExperience) === null || _this$fetchExperience4 === void 0 || _this$fetchExperience4.success();
699
380
  }
700
- _context3.next = 15;
381
+ _context.next = 15;
701
382
  break;
702
383
  case 12:
703
- _context3.prev = 12;
704
- _context3.t0 = _context3["catch"](4);
384
+ _context.prev = 12;
385
+ _context.t0 = _context["catch"](4);
705
386
  (_this$fetchExperience5 = this.fetchExperience) === null || _this$fetchExperience5 === void 0 || _this$fetchExperience5.failure({
706
- reason: "Prefetch promise rejected: ".concat(_context3.t0.message)
387
+ reason: "Prefetch promise rejected: ".concat(_context.t0.message)
707
388
  });
708
389
  case 15:
709
- _context3.prev = 15;
710
- // Clean up in-flight markers so subsequent fetches (e.g. refreshSubscriptions) are not blocked
390
+ _context.prev = 15;
391
+ // Clean up in-flight markers so subsequent fetches are not blocked
711
392
  prefetchedData.resourceIds.forEach(function (resourceId) {
712
- _this7.syncBlockFetchDataRequests.delete(resourceId);
393
+ _this3.syncBlockFetchDataRequests.delete(resourceId);
713
394
  });
714
- return _context3.finish(15);
395
+ return _context.finish(15);
715
396
  case 18:
716
397
  case "end":
717
- return _context3.stop();
398
+ return _context.stop();
718
399
  }
719
- }, _callee2, this, [[4, 12, 15, 18]]);
400
+ }, _callee, this, [[4, 12, 15, 18]]);
720
401
  }));
721
402
  function processPrefetchedData(_x) {
722
403
  return _processPrefetchedData.apply(this, arguments);
@@ -732,56 +413,56 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
732
413
  }, {
733
414
  key: "fetchSyncBlocksData",
734
415
  value: (function () {
735
- var _fetchSyncBlocksData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(syncBlockNodes) {
736
- var _this8 = this,
416
+ var _fetchSyncBlocksData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(syncBlockNodes) {
417
+ var _this4 = this,
737
418
  _this$fetchExperience6;
738
419
  var nodesToFetch, data, _this$processFetchedD2, hasUnexpectedError, hasExpectedError, _this$fetchExperience7, _this$fetchExperience8, _this$fetchExperience9;
739
- return _regeneratorRuntime.wrap(function _callee3$(_context4) {
740
- while (1) switch (_context4.prev = _context4.next) {
420
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
421
+ while (1) switch (_context2.prev = _context2.next) {
741
422
  case 0:
742
423
  if (!(syncBlockNodes.length === 0)) {
743
- _context4.next = 2;
424
+ _context2.next = 2;
744
425
  break;
745
426
  }
746
- return _context4.abrupt("return");
427
+ return _context2.abrupt("return");
747
428
  case 2:
748
429
  // Don't fetch for not_found error since the source is already deleted
749
430
  nodesToFetch = [];
750
431
  syncBlockNodes.forEach(function (node) {
751
432
  var _existingSyncBlock$er;
752
- if (_this8.syncBlockFetchDataRequests.get(node.attrs.resourceId)) {
433
+ if (_this4.syncBlockFetchDataRequests.get(node.attrs.resourceId)) {
753
434
  return;
754
435
  }
755
- var existingSyncBlock = _this8.getFromCache(node.attrs.resourceId);
436
+ var existingSyncBlock = _this4.getFromCache(node.attrs.resourceId);
756
437
  if ((existingSyncBlock === null || existingSyncBlock === void 0 || (_existingSyncBlock$er = existingSyncBlock.error) === null || _existingSyncBlock$er === void 0 ? void 0 : _existingSyncBlock$er.type) === SyncBlockError.NotFound) {
757
438
  return;
758
439
  }
759
440
  nodesToFetch.push(node);
760
441
  });
761
442
  if (!(nodesToFetch.length === 0)) {
762
- _context4.next = 6;
443
+ _context2.next = 6;
763
444
  break;
764
445
  }
765
- return _context4.abrupt("return");
446
+ return _context2.abrupt("return");
766
447
  case 6:
767
448
  if (this.dataProvider) {
768
- _context4.next = 8;
449
+ _context2.next = 8;
769
450
  break;
770
451
  }
771
452
  throw new Error('Data provider not set');
772
453
  case 8:
773
454
  nodesToFetch.forEach(function (node) {
774
- _this8.syncBlockFetchDataRequests.set(node.attrs.resourceId, true);
455
+ _this4.syncBlockFetchDataRequests.set(node.attrs.resourceId, true);
775
456
  });
776
457
  (_this$fetchExperience6 = this.fetchExperience) === null || _this$fetchExperience6 === void 0 || _this$fetchExperience6.start({});
777
- _context4.next = 12;
458
+ _context2.next = 12;
778
459
  return this.dataProvider.fetchNodesData(nodesToFetch).finally(function () {
779
460
  nodesToFetch.forEach(function (node) {
780
- _this8.syncBlockFetchDataRequests.delete(node.attrs.resourceId);
461
+ _this4.syncBlockFetchDataRequests.delete(node.attrs.resourceId);
781
462
  });
782
463
  });
783
464
  case 12:
784
- data = _context4.sent;
465
+ data = _context2.sent;
785
466
  _this$processFetchedD2 = this.processFetchedData(data), hasUnexpectedError = _this$processFetchedD2.hasUnexpectedError, hasExpectedError = _this$processFetchedD2.hasExpectedError;
786
467
  if (hasUnexpectedError) {
787
468
  (_this$fetchExperience7 = this.fetchExperience) === null || _this$fetchExperience7 === void 0 || _this$fetchExperience7.failure({
@@ -796,9 +477,9 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
796
477
  }
797
478
  case 15:
798
479
  case "end":
799
- return _context4.stop();
480
+ return _context2.stop();
800
481
  }
801
- }, _callee3, this);
482
+ }, _callee2, this);
802
483
  }));
803
484
  function fetchSyncBlocksData(_x2) {
804
485
  return _fetchSyncBlocksData.apply(this, arguments);
@@ -808,7 +489,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
808
489
  }, {
809
490
  key: "processFetchedData",
810
491
  value: function processFetchedData(data) {
811
- var _this9 = this;
492
+ var _this5 = this;
812
493
  if (!data) {
813
494
  return {
814
495
  hasUnexpectedError: false,
@@ -820,28 +501,28 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
820
501
  data.forEach(function (syncBlockInstance) {
821
502
  var _resolvedSyncBlockIns;
822
503
  if (!syncBlockInstance.resourceId) {
823
- var _syncBlockInstance$er3, _syncBlockInstance$er4, _this9$fireAnalyticsE;
824
- var payload = ((_syncBlockInstance$er3 = syncBlockInstance.error) === null || _syncBlockInstance$er3 === void 0 ? void 0 : _syncBlockInstance$er3.reason) || ((_syncBlockInstance$er4 = syncBlockInstance.error) === null || _syncBlockInstance$er4 === void 0 ? void 0 : _syncBlockInstance$er4.type) || 'Returned sync block instance does not have resource id';
825
- (_this9$fireAnalyticsE = _this9.fireAnalyticsEvent) === null || _this9$fireAnalyticsE === void 0 || _this9$fireAnalyticsE.call(_this9, fetchErrorPayload(payload));
504
+ var _syncBlockInstance$er, _syncBlockInstance$er2, _this5$fireAnalyticsE;
505
+ var payload = ((_syncBlockInstance$er = syncBlockInstance.error) === null || _syncBlockInstance$er === void 0 ? void 0 : _syncBlockInstance$er.reason) || ((_syncBlockInstance$er2 = syncBlockInstance.error) === null || _syncBlockInstance$er2 === void 0 ? void 0 : _syncBlockInstance$er2.type) || 'Returned sync block instance does not have resource id';
506
+ (_this5$fireAnalyticsE = _this5.fireAnalyticsEvent) === null || _this5$fireAnalyticsE === void 0 || _this5$fireAnalyticsE.call(_this5, fetchErrorPayload(payload));
826
507
  return;
827
508
  }
828
- var existingSyncBlock = _this9.getFromCache(syncBlockInstance.resourceId);
509
+ var existingSyncBlock = _this5.getFromCache(syncBlockInstance.resourceId);
829
510
  var resolvedSyncBlockInstance = existingSyncBlock ? resolveSyncBlockInstance(existingSyncBlock, syncBlockInstance) : syncBlockInstance;
830
- _this9.updateCache(resolvedSyncBlockInstance);
511
+ _this5.updateCache(resolvedSyncBlockInstance);
831
512
 
832
513
  // Check if this is a newly added unpublished sync block and notify
833
514
  // Only trigger for sync blocks that were just added (not refreshed or loaded on page init)
834
- if (!syncBlockInstance.error && ((_resolvedSyncBlockIns = resolvedSyncBlockInstance.data) === null || _resolvedSyncBlockIns === void 0 ? void 0 : _resolvedSyncBlockIns.status) === 'unpublished' && _this9.newlyAddedSyncBlocks.has(syncBlockInstance.resourceId) && _this9.onUnpublishedSyncBlockDetected) {
515
+ if (!syncBlockInstance.error && ((_resolvedSyncBlockIns = resolvedSyncBlockInstance.data) === null || _resolvedSyncBlockIns === void 0 ? void 0 : _resolvedSyncBlockIns.status) === 'unpublished' && _this5.newlyAddedSyncBlocks.has(syncBlockInstance.resourceId) && _this5.onUnpublishedSyncBlockDetected) {
835
516
  // Remove from newly added set after checking to prevent duplicate flags
836
- _this9.newlyAddedSyncBlocks.delete(syncBlockInstance.resourceId);
837
- _this9.onUnpublishedSyncBlockDetected(resolvedSyncBlockInstance.resourceId);
838
- } else if (_this9.newlyAddedSyncBlocks.has(syncBlockInstance.resourceId)) {
517
+ _this5.newlyAddedSyncBlocks.delete(syncBlockInstance.resourceId);
518
+ _this5.onUnpublishedSyncBlockDetected(resolvedSyncBlockInstance.resourceId);
519
+ } else if (_this5.newlyAddedSyncBlocks.has(syncBlockInstance.resourceId)) {
839
520
  // Remove from newly added set even if not unpublished (to clean up)
840
- _this9.newlyAddedSyncBlocks.delete(syncBlockInstance.resourceId);
521
+ _this5.newlyAddedSyncBlocks.delete(syncBlockInstance.resourceId);
841
522
  }
842
523
  if (syncBlockInstance.error) {
843
- var _this9$fireAnalyticsE2;
844
- (_this9$fireAnalyticsE2 = _this9.fireAnalyticsEvent) === null || _this9$fireAnalyticsE2 === void 0 || _this9$fireAnalyticsE2.call(_this9, fetchErrorPayload(syncBlockInstance.error.reason || syncBlockInstance.error.type, syncBlockInstance.resourceId));
524
+ var _this5$fireAnalyticsE2;
525
+ (_this5$fireAnalyticsE2 = _this5.fireAnalyticsEvent) === null || _this5$fireAnalyticsE2 === void 0 || _this5$fireAnalyticsE2.call(_this5, fetchErrorPayload(syncBlockInstance.error.reason || syncBlockInstance.error.type, syncBlockInstance.resourceId));
845
526
  if (syncBlockInstance.error.type === SyncBlockError.NotFound || syncBlockInstance.error.type === SyncBlockError.Forbidden) {
846
527
  hasExpectedError = true;
847
528
  } else if (syncBlockInstance.error) {
@@ -849,13 +530,13 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
849
530
  }
850
531
  return;
851
532
  }
852
- var callbacks = _this9.subscriptions.get(syncBlockInstance.resourceId);
533
+ var callbacks = _this5._subscriptionManager.getSubscriptions().get(syncBlockInstance.resourceId);
853
534
  var localIds = callbacks ? Object.keys(callbacks) : [];
854
535
  localIds.forEach(function (localId) {
855
- var _this9$fireAnalyticsE3, _syncBlockInstance$da2;
856
- (_this9$fireAnalyticsE3 = _this9.fireAnalyticsEvent) === null || _this9$fireAnalyticsE3 === void 0 || _this9$fireAnalyticsE3.call(_this9, fetchSuccessPayload(syncBlockInstance.resourceId, localId, (_syncBlockInstance$da2 = syncBlockInstance.data) === null || _syncBlockInstance$da2 === void 0 ? void 0 : _syncBlockInstance$da2.product));
536
+ var _this5$fireAnalyticsE3, _syncBlockInstance$da;
537
+ (_this5$fireAnalyticsE3 = _this5.fireAnalyticsEvent) === null || _this5$fireAnalyticsE3 === void 0 || _this5$fireAnalyticsE3.call(_this5, fetchSuccessPayload(syncBlockInstance.resourceId, localId, (_syncBlockInstance$da = syncBlockInstance.data) === null || _syncBlockInstance$da === void 0 ? void 0 : _syncBlockInstance$da.product));
857
538
  });
858
- _this9.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
539
+ _this5.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
859
540
  });
860
541
  return {
861
542
  hasUnexpectedError: hasUnexpectedError,
@@ -882,182 +563,54 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
882
563
  value: function updateCache(syncBlock) {
883
564
  var resourceId = syncBlock.resourceId;
884
565
  if (resourceId) {
885
- var _this$dataProvider4;
886
- (_this$dataProvider4 = this.dataProvider) === null || _this$dataProvider4 === void 0 || _this$dataProvider4.updateCache(_defineProperty({}, resourceId, syncBlock), {
566
+ var _this$dataProvider3;
567
+ (_this$dataProvider3 = this.dataProvider) === null || _this$dataProvider3 === void 0 || _this$dataProvider3.updateCache(_defineProperty({}, resourceId, syncBlock), {
887
568
  strategy: 'merge',
888
569
  source: 'network'
889
570
  });
890
- var callbacks = this.subscriptions.get(resourceId);
891
- if (callbacks) {
892
- Object.values(callbacks).forEach(function (callback) {
893
- callback(syncBlock);
894
- });
895
- }
571
+ this._subscriptionManager.notifySubscriptionCallbacks(resourceId, syncBlock);
896
572
  this.updateSessionCache(resourceId);
897
573
  }
898
574
  }
899
- }, {
900
- key: "updateSourceTitleSubscriptions",
901
- value: function updateSourceTitleSubscriptions(resourceId, title) {
902
- var callbacks = this.titleSubscriptions.get(resourceId);
903
- if (callbacks) {
904
- Object.values(callbacks).forEach(function (callback) {
905
- callback(title);
906
- });
907
- }
908
- }
909
575
  }, {
910
576
  key: "getFromCache",
911
577
  value: function getFromCache(resourceId) {
912
- var _this$dataProvider5;
578
+ var _this$dataProvider4;
913
579
  var syncBlockNode = createSyncBlockNode('', resourceId);
914
- return (_this$dataProvider5 = this.dataProvider) === null || _this$dataProvider5 === void 0 || (_this$dataProvider5 = _this$dataProvider5.getNodeDataFromCache(syncBlockNode)) === null || _this$dataProvider5 === void 0 ? void 0 : _this$dataProvider5.data;
580
+ return (_this$dataProvider4 = this.dataProvider) === null || _this$dataProvider4 === void 0 || (_this$dataProvider4 = _this$dataProvider4.getNodeDataFromCache(syncBlockNode)) === null || _this$dataProvider4 === void 0 ? void 0 : _this$dataProvider4.data;
915
581
  }
916
582
  }, {
917
583
  key: "deleteFromCache",
918
584
  value: function deleteFromCache(resourceId) {
919
- var _this$dataProvider6;
920
- (_this$dataProvider6 = this.dataProvider) === null || _this$dataProvider6 === void 0 || _this$dataProvider6.removeFromCache([resourceId]);
921
- if (this._providerFactoryManager && fg('platform_synced_block_patch_5')) {
922
- this._providerFactoryManager.deleteFactory(resourceId);
923
- } else {
924
- this.providerFactories.delete(resourceId);
925
- }
585
+ var _this$dataProvider5;
586
+ (_this$dataProvider5 = this.dataProvider) === null || _this$dataProvider5 === void 0 || _this$dataProvider5.removeFromCache([resourceId]);
587
+ this._providerFactoryManager.deleteFactory(resourceId);
926
588
  }
927
589
  }, {
928
590
  key: "debouncedBatchedFetchSyncBlocks",
929
591
  value: function debouncedBatchedFetchSyncBlocks(resourceId) {
930
- if (this._batchFetcher && fg('platform_synced_block_patch_5')) {
931
- this._batchFetcher.queueFetch(resourceId);
932
- return;
933
- }
934
- // Only add to pending requests if there are active subscriptions for this resource
935
- if (this.subscriptions.has(resourceId) && Object.keys(this.subscriptions.get(resourceId) || {}).length > 0) {
936
- this.pendingFetchRequests.add(resourceId);
937
- this.scheduledBatchFetch();
938
- } else {
939
- this.pendingFetchRequests.delete(resourceId);
940
- }
592
+ this._batchFetcher.queueFetch(resourceId);
941
593
  }
942
594
  }, {
943
595
  key: "setSSRDataInSessionCache",
944
596
  value: function setSSRDataInSessionCache(resourceIds) {
945
- var _this0 = this;
597
+ var _this6 = this;
946
598
  if (!resourceIds || resourceIds.length === 0) {
947
599
  return;
948
600
  }
949
601
  resourceIds.forEach(function (resourceId) {
950
- _this0.updateSessionCache(resourceId);
602
+ _this6.updateSessionCache(resourceId);
951
603
  });
952
604
  }
953
605
  }, {
954
606
  key: "subscribeToSyncBlock",
955
607
  value: function subscribeToSyncBlock(resourceId, localId, callback) {
956
- var _this$dataProvider7,
957
- _this1 = this;
958
- // Cancel any pending cache deletion for this resourceId.
959
- // This handles the case where a block is moved - the old component unmounts
960
- // (scheduling deletion) but the new component mounts and subscribes before
961
- // the deletion timeout fires.
962
- var pendingDeletion = this.pendingCacheDeletions.get(resourceId);
963
- if (pendingDeletion) {
964
- clearTimeout(pendingDeletion);
965
- this.pendingCacheDeletions.delete(resourceId);
966
- }
967
-
968
- // add to subscriptions map
969
- var resourceSubscriptions = this.subscriptions.get(resourceId) || {};
970
- var isNewResourceSubscription = Object.keys(resourceSubscriptions).length === 0;
971
- this.subscriptions.set(resourceId, _objectSpread(_objectSpread({}, resourceSubscriptions), {}, _defineProperty({}, localId, callback)));
972
-
973
- // New subscription means new reference synced block is added to the document
974
- this.isCacheDirty = true;
975
-
976
- // Notify listeners if this is a new resource subscription
977
- if (isNewResourceSubscription) {
978
- this.notifySubscriptionChangeListeners();
979
- }
980
- var syncBlockNode = createSyncBlockNode(localId, resourceId);
981
- var cachedData = (_this$dataProvider7 = this.dataProvider) === null || _this$dataProvider7 === void 0 || (_this$dataProvider7 = _this$dataProvider7.getNodeDataFromCache(syncBlockNode)) === null || _this$dataProvider7 === void 0 ? void 0 : _this$dataProvider7.data;
982
- if (cachedData) {
983
- callback(cachedData);
984
- } else {
985
- this.debouncedBatchedFetchSyncBlocks(resourceId);
986
- }
987
-
988
- // Set up GraphQL subscription if real-time subscriptions are enabled
989
- var useRealTime = this._subscriptionManager && fg('platform_synced_block_patch_5') ? this._subscriptionManager.shouldUseRealTime() : this.useRealTimeSubscriptions;
990
- if (useRealTime) {
991
- this.setupGraphQLSubscription(resourceId);
992
- }
993
- return function () {
994
- var resourceSubscriptions = _this1.subscriptions.get(resourceId);
995
- if (resourceSubscriptions) {
996
- // Unsubscription means a reference synced block is removed from the document
997
- _this1.isCacheDirty = true;
998
- delete resourceSubscriptions[localId];
999
- if (Object.keys(resourceSubscriptions).length === 0) {
1000
- _this1.subscriptions.delete(resourceId);
1001
-
1002
- // Clean up GraphQL subscription when no more local subscribers
1003
- _this1.cleanupGraphQLSubscription(resourceId);
1004
-
1005
- // Notify listeners that subscription was removed
1006
- _this1.notifySubscriptionChangeListeners();
1007
-
1008
- // Delay cache deletion to handle block moves (unmount/remount).
1009
- // When a block is moved, the old component unmounts before the new one mounts.
1010
- // By delaying deletion, we give the new component time to subscribe and
1011
- // cancel this pending deletion, preserving the cached data.
1012
- // TODO: EDITOR-4152 - Rework this logic
1013
- var deletionTimeout = setTimeout(function () {
1014
- // Only delete if still no subscribers (wasn't re-subscribed)
1015
- if (!_this1.subscriptions.has(resourceId)) {
1016
- _this1.deleteFromCache(resourceId);
1017
- }
1018
- _this1.pendingCacheDeletions.delete(resourceId);
1019
- }, 1000);
1020
- _this1.pendingCacheDeletions.set(resourceId, deletionTimeout);
1021
- } else {
1022
- _this1.subscriptions.set(resourceId, resourceSubscriptions);
1023
- }
1024
- }
1025
- };
608
+ return this._subscriptionManager.subscribeToSyncBlock(resourceId, localId, callback);
1026
609
  }
1027
610
  }, {
1028
611
  key: "subscribeToSourceTitle",
1029
612
  value: function subscribeToSourceTitle(node, callback) {
1030
- var _cachedData$data,
1031
- _this10 = this;
1032
- // check node is a sync block, as we only support sync block subscriptions
1033
- if (node.type.name !== 'syncBlock') {
1034
- return function () {};
1035
- }
1036
- var _node$attrs = node.attrs,
1037
- resourceId = _node$attrs.resourceId,
1038
- localId = _node$attrs.localId;
1039
- if (!localId || !resourceId) {
1040
- return function () {};
1041
- }
1042
- var cachedData = this.getFromCache(resourceId);
1043
- if (cachedData !== null && cachedData !== void 0 && (_cachedData$data = cachedData.data) !== null && _cachedData$data !== void 0 && _cachedData$data.sourceTitle) {
1044
- callback(cachedData.data.sourceTitle);
1045
- }
1046
-
1047
- // add to subscriptions map
1048
- var resourceSubscriptions = this.titleSubscriptions.get(resourceId) || {};
1049
- this.titleSubscriptions.set(resourceId, _objectSpread(_objectSpread({}, resourceSubscriptions), {}, _defineProperty({}, localId, callback)));
1050
- return function () {
1051
- var resourceSubscriptions = _this10.titleSubscriptions.get(resourceId);
1052
- if (resourceSubscriptions) {
1053
- delete resourceSubscriptions[localId];
1054
- if (Object.keys(resourceSubscriptions).length === 0) {
1055
- _this10.titleSubscriptions.delete(resourceId);
1056
- } else {
1057
- _this10.titleSubscriptions.set(resourceId, resourceSubscriptions);
1058
- }
1059
- }
1060
- };
613
+ return this._subscriptionManager.subscribeToSourceTitle(node, callback);
1061
614
  }
1062
615
  }, {
1063
616
  key: "subscribe",
@@ -1067,19 +620,19 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
1067
620
  if (node.type.name !== 'syncBlock') {
1068
621
  throw new Error('Only sync block node subscriptions are supported');
1069
622
  }
1070
- var _node$attrs2 = node.attrs,
1071
- resourceId = _node$attrs2.resourceId,
1072
- localId = _node$attrs2.localId;
623
+ var _node$attrs = node.attrs,
624
+ resourceId = _node$attrs.resourceId,
625
+ localId = _node$attrs.localId;
1073
626
  if (!localId || !resourceId) {
1074
627
  throw new Error('Missing local id or resource id');
1075
628
  }
1076
- return this.subscribeToSyncBlock(resourceId, localId, callback);
629
+ return this._subscriptionManager.subscribeToSyncBlock(resourceId, localId, callback);
1077
630
  } catch (error) {
1078
- var _this$fireAnalyticsEv7;
631
+ var _this$fireAnalyticsEv4;
1079
632
  logException(error, {
1080
633
  location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
1081
634
  });
1082
- (_this$fireAnalyticsEv7 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv7 === void 0 || _this$fireAnalyticsEv7.call(this, fetchErrorPayload(error.message));
635
+ (_this$fireAnalyticsEv4 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv4 === void 0 || _this$fireAnalyticsEv4.call(this, fetchErrorPayload(error.message));
1083
636
  return function () {};
1084
637
  }
1085
638
  }
@@ -1102,148 +655,12 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
1102
655
  }, {
1103
656
  key: "getProviderFactory",
1104
657
  value: function getProviderFactory(resourceId) {
1105
- if (this._providerFactoryManager && fg('platform_synced_block_patch_5')) {
1106
- return this._providerFactoryManager.getProviderFactory(resourceId);
1107
- }
1108
- if (!this.dataProvider) {
1109
- var _this$fireAnalyticsEv8;
1110
- var error = new Error('Data provider not set');
1111
- logException(error, {
1112
- location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
1113
- });
1114
- (_this$fireAnalyticsEv8 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv8 === void 0 || _this$fireAnalyticsEv8.call(this, fetchErrorPayload(error.message));
1115
- return undefined;
1116
- }
1117
- var _this$dataProvider$ge = this.dataProvider.getSyncedBlockRendererProviderOptions(),
1118
- parentDataProviders = _this$dataProvider$ge.parentDataProviders,
1119
- providerCreator = _this$dataProvider$ge.providerCreator;
1120
- var providerFactory = this.providerFactories.get(resourceId);
1121
- if (!providerFactory) {
1122
- providerFactory = ProviderFactory.create({
1123
- mentionProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.mentionProvider,
1124
- profilecardProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.profilecardProvider,
1125
- taskDecisionProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.taskDecisionProvider
1126
- });
1127
- this.providerFactories.set(resourceId, providerFactory);
1128
- } else {
1129
- if (parentDataProviders !== null && parentDataProviders !== void 0 && parentDataProviders.mentionProvider) {
1130
- providerFactory.setProvider('mentionProvider', parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.mentionProvider);
1131
- }
1132
- if (parentDataProviders !== null && parentDataProviders !== void 0 && parentDataProviders.profilecardProvider) {
1133
- providerFactory.setProvider('profilecardProvider', parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.profilecardProvider);
1134
- }
1135
- if (parentDataProviders !== null && parentDataProviders !== void 0 && parentDataProviders.taskDecisionProvider) {
1136
- providerFactory.setProvider('taskDecisionProvider', parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.taskDecisionProvider);
1137
- }
1138
- }
1139
- if (providerCreator) {
1140
- try {
1141
- this.retrieveDynamicProviders(resourceId, providerFactory, providerCreator);
1142
- } catch (error) {
1143
- var _this$fireAnalyticsEv9;
1144
- logException(error, {
1145
- location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
1146
- });
1147
- (_this$fireAnalyticsEv9 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv9 === void 0 || _this$fireAnalyticsEv9.call(this, fetchErrorPayload(error.message, resourceId));
1148
- }
1149
- }
1150
- return providerFactory;
658
+ return this._providerFactoryManager.getProviderFactory(resourceId);
1151
659
  }
1152
660
  }, {
1153
661
  key: "getSSRProviders",
1154
662
  value: function getSSRProviders(resourceId) {
1155
- if (this._providerFactoryManager && fg('platform_synced_block_patch_5')) {
1156
- return this._providerFactoryManager.getSSRProviders(resourceId);
1157
- }
1158
- if (!this.dataProvider) {
1159
- return null;
1160
- }
1161
- var _this$dataProvider$ge2 = this.dataProvider.getSyncedBlockRendererProviderOptions(),
1162
- providerCreator = _this$dataProvider$ge2.providerCreator;
1163
- if (!(providerCreator !== null && providerCreator !== void 0 && providerCreator.createSSRMediaProvider)) {
1164
- return null;
1165
- }
1166
- var parsedResourceId = parseResourceId(resourceId);
1167
- if (!parsedResourceId) {
1168
- return null;
1169
- }
1170
- var contentId = parsedResourceId.contentId,
1171
- contentProduct = parsedResourceId.product;
1172
- try {
1173
- var mediaProvider = providerCreator.createSSRMediaProvider({
1174
- contentId: contentId,
1175
- contentProduct: contentProduct
1176
- });
1177
- if (mediaProvider) {
1178
- return {
1179
- media: mediaProvider
1180
- };
1181
- }
1182
- } catch (error) {
1183
- logException(error, {
1184
- location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
1185
- });
1186
- }
1187
- return null;
1188
- }
1189
- }, {
1190
- key: "retrieveDynamicProviders",
1191
- value: function retrieveDynamicProviders(resourceId, providerFactory, providerCreator) {
1192
- var _syncBlock$data2, _syncBlock$data3;
1193
- if (!this.dataProvider) {
1194
- throw new Error('Data provider not set');
1195
- }
1196
- var hasMediaProvider = providerFactory.hasProvider('mediaProvider');
1197
- var hasEmojiProvider = providerFactory.hasProvider('emojiProvider');
1198
- var hasCardProvider = providerFactory.hasProvider('cardProvider');
1199
- if (hasMediaProvider && hasEmojiProvider && hasCardProvider) {
1200
- return;
1201
- }
1202
- var syncBlock = this.getFromCache(resourceId);
1203
- if (!(syncBlock !== null && syncBlock !== void 0 && syncBlock.data)) {
1204
- return;
1205
- }
1206
- if (!syncBlock.data.sourceAri || !syncBlock.data.product) {
1207
- var _this$fireAnalyticsEv0;
1208
- (_this$fireAnalyticsEv0 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv0 === void 0 || _this$fireAnalyticsEv0.call(this, fetchErrorPayload('Sync block source ari or product not found'));
1209
- return;
1210
- }
1211
- var parentInfo = this.dataProvider.retrieveSyncBlockParentInfo((_syncBlock$data2 = syncBlock.data) === null || _syncBlock$data2 === void 0 ? void 0 : _syncBlock$data2.sourceAri, (_syncBlock$data3 = syncBlock.data) === null || _syncBlock$data3 === void 0 ? void 0 : _syncBlock$data3.product);
1212
- if (!parentInfo) {
1213
- throw new Error('Unable to retrieve sync block parent info');
1214
- }
1215
- var contentId = parentInfo.contentId,
1216
- contentProduct = parentInfo.contentProduct;
1217
- if (!hasMediaProvider) {
1218
- if (providerCreator.createMediaProvider && contentId && contentProduct) {
1219
- var mediaProvider = providerCreator.createMediaProvider({
1220
- contentProduct: contentProduct,
1221
- contentId: contentId
1222
- });
1223
- if (mediaProvider) {
1224
- providerFactory.setProvider('mediaProvider', mediaProvider);
1225
- }
1226
- }
1227
- }
1228
- if (!hasEmojiProvider) {
1229
- if (providerCreator.createEmojiProvider && contentId && contentProduct) {
1230
- var emojiProvider = providerCreator.createEmojiProvider({
1231
- contentProduct: contentProduct,
1232
- contentId: contentId
1233
- });
1234
- if (emojiProvider) {
1235
- providerFactory.setProvider('emojiProvider', emojiProvider);
1236
- }
1237
- }
1238
- }
1239
- if (!hasCardProvider) {
1240
- if (providerCreator.createSmartLinkProvider) {
1241
- var smartLinkProvider = providerCreator.createSmartLinkProvider();
1242
- if (smartLinkProvider) {
1243
- providerFactory.setProvider('cardProvider', smartLinkProvider);
1244
- }
1245
- }
1246
- }
663
+ return this._providerFactoryManager.getSSRProviders(resourceId);
1247
664
  }
1248
665
 
1249
666
  /**
@@ -1254,49 +671,49 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
1254
671
  }, {
1255
672
  key: "flush",
1256
673
  value: (function () {
1257
- var _flush = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
1258
- var _this11 = this;
1259
- var success, syncedBlocksToFlush, _this$saveExperience, blocks, _iterator4, _step4, _loop2, updateResult, _this$saveExperience2, _this$fireAnalyticsEv1, _this$saveExperience3, _this$fireAnalyticsEv10, _this$saveExperience4;
1260
- return _regeneratorRuntime.wrap(function _callee4$(_context6) {
1261
- while (1) switch (_context6.prev = _context6.next) {
674
+ var _flush = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
675
+ var _this7 = this;
676
+ var success, syncedBlocksToFlush, _this$saveExperience, blocks, _iterator, _step, _loop, updateResult, _this$saveExperience2, _this$fireAnalyticsEv5, _this$saveExperience3, _this$fireAnalyticsEv6, _this$saveExperience4;
677
+ return _regeneratorRuntime.wrap(function _callee3$(_context4) {
678
+ while (1) switch (_context4.prev = _context4.next) {
1262
679
  case 0:
1263
680
  if (this.isCacheDirty) {
1264
- _context6.next = 2;
681
+ _context4.next = 2;
1265
682
  break;
1266
683
  }
1267
- return _context6.abrupt("return", true);
684
+ return _context4.abrupt("return", true);
1268
685
  case 2:
1269
686
  if (!this.isFlushInProgress) {
1270
- _context6.next = 7;
687
+ _context4.next = 7;
1271
688
  break;
1272
689
  }
1273
690
  // Mark that another flush is needed after the current one completes
1274
691
  this.flushNeededAfterCurrent = true;
1275
692
 
1276
693
  // We return true here because we know the pending flush will handle the dirty cache
1277
- return _context6.abrupt("return", true);
694
+ return _context4.abrupt("return", true);
1278
695
  case 7:
1279
696
  this.isFlushInProgress = true;
1280
697
  case 8:
1281
698
  success = true; // a copy of the subscriptions STRUCTURE (without the callbacks)
1282
699
  // To be saved as the last flushed structure if the flush is successful
1283
700
  syncedBlocksToFlush = {};
1284
- _context6.prev = 10;
701
+ _context4.prev = 10;
1285
702
  if (this.dataProvider) {
1286
- _context6.next = 13;
703
+ _context4.next = 13;
1287
704
  break;
1288
705
  }
1289
706
  throw new Error('Data provider not set');
1290
707
  case 13:
1291
708
  blocks = []; // First, build the complete subscription structure
1292
- _iterator4 = _createForOfIteratorHelper(this.subscriptions.entries());
1293
- _context6.prev = 15;
1294
- _loop2 = /*#__PURE__*/_regeneratorRuntime.mark(function _loop2() {
1295
- var _step4$value, resourceId, callbacks;
1296
- return _regeneratorRuntime.wrap(function _loop2$(_context5) {
1297
- while (1) switch (_context5.prev = _context5.next) {
709
+ _iterator = _createForOfIteratorHelper(this._subscriptionManager.getSubscriptions().entries());
710
+ _context4.prev = 15;
711
+ _loop = /*#__PURE__*/_regeneratorRuntime.mark(function _loop() {
712
+ var _step$value, resourceId, callbacks;
713
+ return _regeneratorRuntime.wrap(function _loop$(_context3) {
714
+ while (1) switch (_context3.prev = _context3.next) {
1298
715
  case 0:
1299
- _step4$value = _slicedToArray(_step4.value, 2), resourceId = _step4$value[0], callbacks = _step4$value[1];
716
+ _step$value = _slicedToArray(_step.value, 2), resourceId = _step$value[0], callbacks = _step$value[1];
1300
717
  syncedBlocksToFlush[resourceId] = {};
1301
718
  Object.keys(callbacks).forEach(function (localId) {
1302
719
  blocks.push({
@@ -1307,38 +724,38 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
1307
724
  });
1308
725
  case 3:
1309
726
  case "end":
1310
- return _context5.stop();
727
+ return _context3.stop();
1311
728
  }
1312
- }, _loop2);
729
+ }, _loop);
1313
730
  });
1314
- _iterator4.s();
731
+ _iterator.s();
1315
732
  case 18:
1316
- if ((_step4 = _iterator4.n()).done) {
1317
- _context6.next = 22;
733
+ if ((_step = _iterator.n()).done) {
734
+ _context4.next = 22;
1318
735
  break;
1319
736
  }
1320
- return _context6.delegateYield(_loop2(), "t0", 20);
737
+ return _context4.delegateYield(_loop(), "t0", 20);
1321
738
  case 20:
1322
- _context6.next = 18;
739
+ _context4.next = 18;
1323
740
  break;
1324
741
  case 22:
1325
- _context6.next = 27;
742
+ _context4.next = 27;
1326
743
  break;
1327
744
  case 24:
1328
- _context6.prev = 24;
1329
- _context6.t1 = _context6["catch"](15);
1330
- _iterator4.e(_context6.t1);
745
+ _context4.prev = 24;
746
+ _context4.t1 = _context4["catch"](15);
747
+ _iterator.e(_context4.t1);
1331
748
  case 27:
1332
- _context6.prev = 27;
1333
- _iterator4.f();
1334
- return _context6.finish(27);
749
+ _context4.prev = 27;
750
+ _iterator.f();
751
+ return _context4.finish(27);
1335
752
  case 30:
1336
753
  if (!isEqual(syncedBlocksToFlush, this.lastFlushedSyncedBlocks)) {
1337
- _context6.next = 33;
754
+ _context4.next = 33;
1338
755
  break;
1339
756
  }
1340
757
  this.isCacheDirty = false; // Reset since we're considering this a successful no-op flush
1341
- return _context6.abrupt("return", true);
758
+ return _context4.abrupt("return", true);
1342
759
  case 33:
1343
760
  // reset isCacheDirty early to prevent race condition
1344
761
  // There is a race condition where if a user makes changes (create/delete) to a reference sync block
@@ -1347,32 +764,32 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
1347
764
  // exactly at a time when the updateReferenceData is being executed asynchronously.
1348
765
  this.isCacheDirty = false;
1349
766
  (_this$saveExperience = this.saveExperience) === null || _this$saveExperience === void 0 || _this$saveExperience.start();
1350
- _context6.next = 37;
767
+ _context4.next = 37;
1351
768
  return this.dataProvider.updateReferenceData(blocks);
1352
769
  case 37:
1353
- updateResult = _context6.sent;
770
+ updateResult = _context4.sent;
1354
771
  if (!updateResult.success) {
1355
772
  success = false;
1356
773
  (_this$saveExperience2 = this.saveExperience) === null || _this$saveExperience2 === void 0 || _this$saveExperience2.failure({
1357
774
  reason: updateResult.error || 'Failed to update reference synced blocks on the document'
1358
775
  });
1359
- (_this$fireAnalyticsEv1 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv1 === void 0 || _this$fireAnalyticsEv1.call(this, updateReferenceErrorPayload(updateResult.error || 'Failed to update reference synced blocks on the document'));
776
+ (_this$fireAnalyticsEv5 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv5 === void 0 || _this$fireAnalyticsEv5.call(this, updateReferenceErrorPayload(updateResult.error || 'Failed to update reference synced blocks on the document'));
1360
777
  }
1361
- _context6.next = 47;
778
+ _context4.next = 47;
1362
779
  break;
1363
780
  case 41:
1364
- _context6.prev = 41;
1365
- _context6.t2 = _context6["catch"](10);
781
+ _context4.prev = 41;
782
+ _context4.t2 = _context4["catch"](10);
1366
783
  success = false;
1367
- logException(_context6.t2, {
784
+ logException(_context4.t2, {
1368
785
  location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
1369
786
  });
1370
787
  (_this$saveExperience3 = this.saveExperience) === null || _this$saveExperience3 === void 0 || _this$saveExperience3.failure({
1371
- reason: _context6.t2.message
788
+ reason: _context4.t2.message
1372
789
  });
1373
- (_this$fireAnalyticsEv10 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv10 === void 0 || _this$fireAnalyticsEv10.call(this, updateReferenceErrorPayload(_context6.t2.message));
790
+ (_this$fireAnalyticsEv6 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv6 === void 0 || _this$fireAnalyticsEv6.call(this, updateReferenceErrorPayload(_context4.t2.message));
1374
791
  case 47:
1375
- _context6.prev = 47;
792
+ _context4.prev = 47;
1376
793
  if (!success) {
1377
794
  // set isCacheDirty back to true for cases where it failed to update the reference synced blocks on the BE
1378
795
  this.isCacheDirty = true;
@@ -1390,18 +807,18 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
1390
807
  // Use setTimeout to avoid deep recursion and run queued flush asynchronously
1391
808
  // Note: flush() handles all exceptions internally and never rejects
1392
809
  this.queuedFlushTimeout = setTimeout(function () {
1393
- _this11.queuedFlushTimeout = undefined;
1394
- void _this11.flush();
810
+ _this7.queuedFlushTimeout = undefined;
811
+ void _this7.flush();
1395
812
  }, 0);
1396
813
  }
1397
- return _context6.finish(47);
814
+ return _context4.finish(47);
1398
815
  case 52:
1399
- return _context6.abrupt("return", success);
816
+ return _context4.abrupt("return", success);
1400
817
  case 53:
1401
818
  case "end":
1402
- return _context6.stop();
819
+ return _context4.stop();
1403
820
  }
1404
- }, _callee4, this, [[10, 41, 47, 52], [15, 24, 27, 30]]);
821
+ }, _callee3, this, [[10, 41, 47, 52], [15, 24, 27, 30]]);
1405
822
  }));
1406
823
  function flush() {
1407
824
  return _flush.apply(this, arguments);
@@ -1411,36 +828,19 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
1411
828
  }, {
1412
829
  key: "destroy",
1413
830
  value: function destroy() {
1414
- var _this$dataProvider8, _this$saveExperience5, _this$fetchExperience0, _this$fetchSourceInfo2;
831
+ var _this$dataProvider6, _this$saveExperience5, _this$fetchExperience0, _this$fetchSourceInfo2;
1415
832
  // Cancel any queued flush to prevent it from running after destroy
1416
833
  if (this.queuedFlushTimeout) {
1417
834
  clearTimeout(this.queuedFlushTimeout);
1418
835
  this.queuedFlushTimeout = undefined;
1419
836
  }
1420
- if (fg('platform_synced_block_patch_5')) {
1421
- var _this$_subscriptionMa, _this$_providerFactor, _this$_batchFetcher;
1422
- (_this$_subscriptionMa = this._subscriptionManager) === null || _this$_subscriptionMa === void 0 || _this$_subscriptionMa.destroy();
1423
- (_this$_providerFactor = this._providerFactoryManager) === null || _this$_providerFactor === void 0 || _this$_providerFactor.destroy();
1424
- (_this$_batchFetcher = this._batchFetcher) === null || _this$_batchFetcher === void 0 || _this$_batchFetcher.destroy();
1425
- }
1426
-
1427
- // Clean up all GraphQL subscriptions first
1428
- this.cleanupAllGraphQLSubscriptions();
1429
- (_this$dataProvider8 = this.dataProvider) === null || _this$dataProvider8 === void 0 || _this$dataProvider8.resetCache();
1430
- this.scheduledBatchFetch.cancel();
1431
- this.pendingFetchRequests.clear();
837
+ this._subscriptionManager.destroy();
838
+ this._providerFactoryManager.destroy();
839
+ this._batchFetcher.destroy();
840
+ (_this$dataProvider6 = this.dataProvider) === null || _this$dataProvider6 === void 0 || _this$dataProvider6.resetCache();
1432
841
  this.dataProvider = undefined;
1433
- this.subscriptions.clear();
1434
- this.titleSubscriptions.clear();
1435
842
  this.syncBlockFetchDataRequests.clear();
1436
843
  this.syncBlockSourceInfoRequests.clear();
1437
- this.isRefreshingSubscriptions = false;
1438
- this.useRealTimeSubscriptions = false;
1439
- this.subscriptionChangeListeners.clear();
1440
- this.providerFactories.forEach(function (providerFactory) {
1441
- providerFactory.destroy();
1442
- });
1443
- this.providerFactories.clear();
1444
844
  (_this$saveExperience5 = this.saveExperience) === null || _this$saveExperience5 === void 0 || _this$saveExperience5.abort({
1445
845
  reason: 'editorDestroyed'
1446
846
  });
@@ -1451,9 +851,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
1451
851
  reason: 'editorDestroyed'
1452
852
  });
1453
853
  this.fireAnalyticsEvent = undefined;
1454
- if (fg('platform_synced_block_patch_5')) {
1455
- syncBlockInMemorySessionCache.clear();
1456
- }
854
+ syncBlockInMemorySessionCache.clear();
1457
855
  }
1458
856
  }]);
1459
857
  }();