@atlaskit/editor-synced-block-provider 4.0.1 → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/cjs/clients/block-service/blockService.js +35 -17
  3. package/dist/cjs/common/types.js +2 -0
  4. package/dist/cjs/providers/block-service/blockServiceAPI.js +16 -1
  5. package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +209 -811
  6. package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +3 -6
  7. package/dist/cjs/store-manager/syncBlockSubscriptionManager.js +180 -17
  8. package/dist/es2019/clients/block-service/blockService.js +16 -3
  9. package/dist/es2019/common/types.js +2 -0
  10. package/dist/es2019/providers/block-service/blockServiceAPI.js +12 -1
  11. package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +78 -595
  12. package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +3 -6
  13. package/dist/es2019/store-manager/syncBlockSubscriptionManager.js +157 -10
  14. package/dist/esm/clients/block-service/blockService.js +34 -16
  15. package/dist/esm/common/types.js +2 -0
  16. package/dist/esm/providers/block-service/blockServiceAPI.js +17 -2
  17. package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +210 -812
  18. package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +3 -6
  19. package/dist/esm/store-manager/syncBlockSubscriptionManager.js +180 -17
  20. package/dist/types/clients/block-service/blockService.d.ts +4 -1
  21. package/dist/types/common/types.d.ts +2 -1
  22. package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +4 -49
  23. package/dist/types/store-manager/syncBlockSubscriptionManager.d.ts +25 -6
  24. package/dist/types-ts4.5/clients/block-service/blockService.d.ts +4 -1
  25. package/dist/types-ts4.5/common/types.d.ts +2 -1
  26. package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +4 -49
  27. package/dist/types-ts4.5/store-manager/syncBlockSubscriptionManager.d.ts +25 -6
  28. package/package.json +4 -7
@@ -1,14 +1,10 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import isEqual from 'lodash/isEqual';
3
- import rafSchedule from 'raf-schd';
4
3
  import { logException } from '@atlaskit/editor-common/monitoring';
5
- import { ProviderFactory } from '@atlaskit/editor-common/provider-factory';
6
- import { fg } from '@atlaskit/platform-feature-flags';
7
4
  import { SyncBlockError } from '../common/types';
8
5
  import { fetchErrorPayload, fetchSuccessPayload, getSourceInfoErrorPayload, updateReferenceErrorPayload } from '../utils/errorHandling';
9
6
  import { getFetchExperience, getFetchSourceInfoExperience, getSaveReferenceExperience } from '../utils/experienceTracking';
10
7
  import { resolveSyncBlockInstance } from '../utils/resolveSyncBlockInstance';
11
- import { parseResourceId } from '../utils/resourceId';
12
8
  import { createSyncBlockNode } from '../utils/utils';
13
9
  import { SyncBlockBatchFetcher } from './syncBlockBatchFetcher';
14
10
  import { syncBlockInMemorySessionCache } from './syncBlockInMemorySessionCache';
@@ -22,73 +18,46 @@ const CACHE_KEY_PREFIX = 'sync-block-data-';
22
18
  // Handles fetching source URL and title for sync blocks.
23
19
  // Can be used in both editor and renderer contexts.
24
20
  export class ReferenceSyncBlockStoreManager {
21
+ // Track the setTimeout handle for queued flush so we can cancel it on destroy
22
+
25
23
  constructor(dataProvider) {
26
24
  var _this$dataProvider;
27
25
  // Keeps track of addition and deletion of reference synced blocks on the document
28
26
  // This starts as true to always flush the cache when document is saved for the first time
29
27
  // to cater the case when a editor session is closed without document being updated right after reference block is deleted
30
28
  _defineProperty(this, "isCacheDirty", true);
31
- _defineProperty(this, "isRefreshingSubscriptions", false);
32
- // Flag to indicate if real-time subscriptions are enabled
33
- _defineProperty(this, "useRealTimeSubscriptions", false);
34
29
  // Keep track of the last flushed subscriptions to optimize cache flushing on document save
35
30
  _defineProperty(this, "lastFlushedSyncedBlocks", {});
36
31
  // Track if a flush operation is currently in progress
37
32
  _defineProperty(this, "isFlushInProgress", false);
38
33
  // Track if another flush is needed after the current one completes
39
34
  _defineProperty(this, "flushNeededAfterCurrent", false);
40
- _defineProperty(this, "pendingFetchRequests", new Set());
41
- _defineProperty(this, "scheduledBatchFetch", rafSchedule(() => {
42
- if (this.pendingFetchRequests.size === 0) {
43
- return;
44
- }
45
- const resourceIds = Array.from(this.pendingFetchRequests);
46
- const syncBlockNodes = resourceIds.map(resId => {
47
- const subscriptions = this.subscriptions.get(resId) || {};
48
- const firstLocalId = Object.keys(subscriptions)[0] || '';
49
- return createSyncBlockNode(firstLocalId, resId);
50
- });
51
- this.pendingFetchRequests.clear();
52
- this.fetchSyncBlocksData(syncBlockNodes).catch(error => {
53
- logException(error, {
54
- location: 'editor-synced-block-provider/referenceSyncBlockStoreManager/batchedFetchSyncBlocks'
55
- });
56
- resourceIds.forEach(resId => {
57
- var _this$fireAnalyticsEv;
58
- (_this$fireAnalyticsEv = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv === void 0 ? void 0 : _this$fireAnalyticsEv.call(this, fetchErrorPayload(error.message, resId));
59
- });
60
- });
61
- }));
62
- this.subscriptions = new Map();
63
- this.titleSubscriptions = new Map();
64
35
  this.dataProvider = dataProvider;
65
36
  this.syncBlockFetchDataRequests = new Map();
66
37
  this.syncBlockSourceInfoRequests = new Map();
67
- this.providerFactories = new Map();
68
- this.pendingCacheDeletions = new Map();
69
- this.graphqlSubscriptions = new Map();
70
- this.subscriptionChangeListeners = new Set();
71
38
  this.newlyAddedSyncBlocks = new Set();
72
- if (fg('platform_synced_block_patch_5')) {
73
- this._subscriptionManager = new SyncBlockSubscriptionManager({
74
- getDataProvider: () => this.dataProvider,
75
- getSubscriptions: () => this.subscriptions,
76
- getFromCache: rid => this.getFromCache(rid),
77
- updateCache: inst => this.updateCache(inst),
78
- fetchSyncBlockSourceInfo: rid => this.fetchSyncBlockSourceInfo(rid),
79
- getFireAnalyticsEvent: () => this.fireAnalyticsEvent
80
- });
81
- this._providerFactoryManager = new SyncBlockProviderFactoryManager({
82
- getDataProvider: () => this.dataProvider,
83
- getFromCache: rid => this.getFromCache(rid),
84
- getFireAnalyticsEvent: () => this.fireAnalyticsEvent
85
- });
86
- this._batchFetcher = new SyncBlockBatchFetcher({
87
- getSubscriptions: () => this.subscriptions,
88
- fetchSyncBlocksData: nodes => this.fetchSyncBlocksData(nodes),
89
- getFireAnalyticsEvent: () => this.fireAnalyticsEvent
90
- });
91
- }
39
+ this._subscriptionManager = new SyncBlockSubscriptionManager({
40
+ getDataProvider: () => this.dataProvider,
41
+ getFromCache: rid => this.getFromCache(rid),
42
+ updateCache: inst => this.updateCache(inst),
43
+ deleteFromCache: rid => this.deleteFromCache(rid),
44
+ debouncedBatchedFetchSyncBlocks: rid => this.debouncedBatchedFetchSyncBlocks(rid),
45
+ fetchSyncBlockSourceInfo: rid => this.fetchSyncBlockSourceInfo(rid),
46
+ getFireAnalyticsEvent: () => this.fireAnalyticsEvent,
47
+ markCacheDirty: () => {
48
+ this.isCacheDirty = true;
49
+ }
50
+ });
51
+ this._providerFactoryManager = new SyncBlockProviderFactoryManager({
52
+ getDataProvider: () => this.dataProvider,
53
+ getFromCache: rid => this.getFromCache(rid),
54
+ getFireAnalyticsEvent: () => this.fireAnalyticsEvent
55
+ });
56
+ this._batchFetcher = new SyncBlockBatchFetcher({
57
+ getSubscriptions: () => this._subscriptionManager.getSubscriptions(),
58
+ fetchSyncBlocksData: nodes => this.fetchSyncBlocksData(nodes),
59
+ getFireAnalyticsEvent: () => this.fireAnalyticsEvent
60
+ });
92
61
 
93
62
  // The provider might have SSR data cache already set, so we need to update the cache in session memory storage
94
63
  this.setSSRDataInSessionCache((_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.getNodeDataCacheKeys());
@@ -101,31 +70,14 @@ export class ReferenceSyncBlockStoreManager {
101
70
  * @param enabled - Whether to enable real-time subscriptions
102
71
  */
103
72
  setRealTimeSubscriptionsEnabled(enabled) {
104
- if (this._subscriptionManager && fg('platform_synced_block_patch_5')) {
105
- this._subscriptionManager.setRealTimeSubscriptionsEnabled(enabled);
106
- return;
107
- }
108
- if (this.useRealTimeSubscriptions === enabled) {
109
- return;
110
- }
111
- this.useRealTimeSubscriptions = enabled;
112
- if (enabled) {
113
- // Set up subscriptions for all currently subscribed blocks
114
- this.setupGraphQLSubscriptionsForAllBlocks();
115
- } else {
116
- // Clean up all GraphQL subscriptions
117
- this.cleanupAllGraphQLSubscriptions();
118
- }
73
+ this._subscriptionManager.setRealTimeSubscriptionsEnabled(enabled);
119
74
  }
120
75
 
121
76
  /**
122
77
  * Checks if real-time subscriptions are currently enabled.
123
78
  */
124
79
  isRealTimeSubscriptionsEnabled() {
125
- if (this._subscriptionManager && fg('platform_synced_block_patch_5')) {
126
- return this._subscriptionManager.isRealTimeSubscriptionsEnabled();
127
- }
128
- return this.useRealTimeSubscriptions;
80
+ return this._subscriptionManager.isRealTimeSubscriptionsEnabled();
129
81
  }
130
82
 
131
83
  /**
@@ -133,10 +85,7 @@ export class ReferenceSyncBlockStoreManager {
133
85
  * Used by React components to render subscription components.
134
86
  */
135
87
  getSubscribedResourceIds() {
136
- if (this._subscriptionManager && fg('platform_synced_block_patch_5')) {
137
- return this._subscriptionManager.getSubscribedResourceIds();
138
- }
139
- return Array.from(this.subscriptions.keys());
88
+ return this._subscriptionManager.getSubscribedResourceIds();
140
89
  }
141
90
 
142
91
  /**
@@ -145,34 +94,7 @@ export class ReferenceSyncBlockStoreManager {
145
94
  * @returns Unsubscribe function to remove the listener
146
95
  */
147
96
  onSubscriptionsChanged(listener) {
148
- if (this._subscriptionManager && fg('platform_synced_block_patch_5')) {
149
- return this._subscriptionManager.onSubscriptionsChanged(listener);
150
- }
151
- this.subscriptionChangeListeners.add(listener);
152
- return () => {
153
- this.subscriptionChangeListeners.delete(listener);
154
- };
155
- }
156
-
157
- /**
158
- * Notifies all subscription change listeners.
159
- */
160
- notifySubscriptionChangeListeners() {
161
- if (this._subscriptionManager && fg('platform_synced_block_patch_5')) {
162
- this._subscriptionManager.notifySubscriptionChangeListeners();
163
- return;
164
- }
165
- this.subscriptionChangeListeners.forEach(listener => {
166
- try {
167
- listener();
168
- } catch (error) {
169
- var _this$fireAnalyticsEv2;
170
- logException(error, {
171
- location: 'editor-synced-block-provider/referenceSyncBlockStoreManager/notifySubscriptionChangeListeners'
172
- });
173
- (_this$fireAnalyticsEv2 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv2 === void 0 ? void 0 : _this$fireAnalyticsEv2.call(this, fetchErrorPayload(error.message));
174
- }
175
- });
97
+ return this._subscriptionManager.onSubscriptionsChanged(listener);
176
98
  }
177
99
 
178
100
  /**
@@ -181,19 +103,7 @@ export class ReferenceSyncBlockStoreManager {
181
103
  * @param syncBlockInstance - The updated sync block instance
182
104
  */
183
105
  handleSubscriptionUpdate(syncBlockInstance) {
184
- if (this._subscriptionManager && fg('platform_synced_block_patch_5')) {
185
- this._subscriptionManager.handleSubscriptionUpdate(syncBlockInstance);
186
- return;
187
- }
188
- if (!syncBlockInstance.resourceId) {
189
- return;
190
- }
191
- const existingSyncBlock = this.getFromCache(syncBlockInstance.resourceId);
192
- const resolvedSyncBlockInstance = existingSyncBlock ? resolveSyncBlockInstance(existingSyncBlock, syncBlockInstance) : syncBlockInstance;
193
- this.updateCache(resolvedSyncBlockInstance);
194
- if (!syncBlockInstance.error) {
195
- this.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
196
- }
106
+ this._subscriptionManager.handleSubscriptionUpdate(syncBlockInstance);
197
107
  }
198
108
  setFireAnalyticsEvent(fireAnalyticsEvent) {
199
109
  this.fireAnalyticsEvent = fireAnalyticsEvent;
@@ -251,143 +161,6 @@ export class ReferenceSyncBlockStoreManager {
251
161
  return undefined;
252
162
  }
253
163
  }
254
-
255
- /**
256
- * Refreshes the subscriptions for all sync blocks.
257
- * This is a fallback polling mechanism when real-time subscriptions are not enabled.
258
- * @returns {Promise<void>}
259
- */
260
- async refreshSubscriptions() {
261
- // Skip polling refresh if real-time subscriptions are enabled
262
- if (this.useRealTimeSubscriptions) {
263
- return;
264
- }
265
- if (this.isRefreshingSubscriptions) {
266
- return;
267
- }
268
- this.isRefreshingSubscriptions = true;
269
- const syncBlocks = [];
270
- for (const [resourceId, callbacks] of this.subscriptions.entries()) {
271
- Object.keys(callbacks).forEach(localId => {
272
- syncBlocks.push(createSyncBlockNode(localId, resourceId));
273
- });
274
- }
275
- try {
276
- // fetch latest data for all subscribed sync blocks
277
- // this function will update the cache and call the subscriptions
278
- await this.fetchSyncBlocksData(syncBlocks);
279
- } catch (error) {
280
- var _this$fireAnalyticsEv3;
281
- logException(error, {
282
- location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
283
- });
284
- (_this$fireAnalyticsEv3 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv3 === void 0 ? void 0 : _this$fireAnalyticsEv3.call(this, fetchErrorPayload(error.message));
285
- } finally {
286
- this.isRefreshingSubscriptions = false;
287
- }
288
- }
289
-
290
- /**
291
- * Sets up a GraphQL subscription for a specific block.
292
- * @param resourceId - The resource ID of the block to subscribe to
293
- */
294
- setupGraphQLSubscription(resourceId) {
295
- var _this$dataProvider3;
296
- if (this._subscriptionManager && fg('platform_synced_block_patch_5')) {
297
- this._subscriptionManager.setupSubscription(resourceId);
298
- return;
299
- }
300
-
301
- // Don't set up duplicate subscriptions
302
- if (this.graphqlSubscriptions.has(resourceId)) {
303
- return;
304
- }
305
- if (!((_this$dataProvider3 = this.dataProvider) !== null && _this$dataProvider3 !== void 0 && _this$dataProvider3.subscribeToBlockUpdates)) {
306
- return;
307
- }
308
- const unsubscribe = this.dataProvider.subscribeToBlockUpdates(resourceId, syncBlockInstance => {
309
- // Handle the subscription update
310
- this.handleGraphQLSubscriptionUpdate(syncBlockInstance);
311
- }, error => {
312
- var _this$fireAnalyticsEv4;
313
- logException(error, {
314
- location: 'editor-synced-block-provider/referenceSyncBlockStoreManager/graphql-subscription'
315
- });
316
- (_this$fireAnalyticsEv4 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv4 === void 0 ? void 0 : _this$fireAnalyticsEv4.call(this, fetchErrorPayload(error.message));
317
- });
318
- if (unsubscribe) {
319
- this.graphqlSubscriptions.set(resourceId, unsubscribe);
320
- }
321
- }
322
-
323
- /**
324
- * Handles updates received from GraphQL subscriptions.
325
- * @param syncBlockInstance - The updated sync block instance
326
- */
327
- handleGraphQLSubscriptionUpdate(syncBlockInstance) {
328
- if (!syncBlockInstance.resourceId) {
329
- return;
330
- }
331
- const existingSyncBlock = this.getFromCache(syncBlockInstance.resourceId);
332
- const resolvedSyncBlockInstance = existingSyncBlock ? resolveSyncBlockInstance(existingSyncBlock, syncBlockInstance) : syncBlockInstance;
333
- this.updateCache(resolvedSyncBlockInstance);
334
- if (!syncBlockInstance.error) {
335
- const callbacks = this.subscriptions.get(syncBlockInstance.resourceId);
336
- const localIds = callbacks ? Object.keys(callbacks) : [];
337
- localIds.forEach(localId => {
338
- var _this$fireAnalyticsEv5, _syncBlockInstance$da;
339
- (_this$fireAnalyticsEv5 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv5 === void 0 ? void 0 : _this$fireAnalyticsEv5.call(this, fetchSuccessPayload(syncBlockInstance.resourceId, localId, (_syncBlockInstance$da = syncBlockInstance.data) === null || _syncBlockInstance$da === void 0 ? void 0 : _syncBlockInstance$da.product));
340
- });
341
- this.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
342
- } else {
343
- var _syncBlockInstance$er, _syncBlockInstance$er2, _this$fireAnalyticsEv6;
344
- const 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);
345
- (_this$fireAnalyticsEv6 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv6 === void 0 ? void 0 : _this$fireAnalyticsEv6.call(this, fetchErrorPayload(errorMessage, syncBlockInstance.resourceId));
346
- }
347
- }
348
-
349
- /**
350
- * Cleans up the GraphQL subscription for a specific block.
351
- * @param resourceId - The resource ID of the block to unsubscribe from
352
- */
353
- cleanupGraphQLSubscription(resourceId) {
354
- if (this._subscriptionManager && fg('platform_synced_block_patch_5')) {
355
- this._subscriptionManager.cleanupSubscription(resourceId);
356
- return;
357
- }
358
- const unsubscribe = this.graphqlSubscriptions.get(resourceId);
359
- if (unsubscribe) {
360
- unsubscribe();
361
- this.graphqlSubscriptions.delete(resourceId);
362
- }
363
- }
364
-
365
- /**
366
- * Sets up GraphQL subscriptions for all currently subscribed blocks.
367
- */
368
- setupGraphQLSubscriptionsForAllBlocks() {
369
- if (this._subscriptionManager && fg('platform_synced_block_patch_5')) {
370
- this._subscriptionManager.setupSubscriptionsForAllBlocks();
371
- return;
372
- }
373
- for (const resourceId of this.subscriptions.keys()) {
374
- this.setupGraphQLSubscription(resourceId);
375
- }
376
- }
377
-
378
- /**
379
- * Cleans up all GraphQL subscriptions.
380
- */
381
- cleanupAllGraphQLSubscriptions() {
382
- if (this._subscriptionManager && fg('platform_synced_block_patch_5')) {
383
- this._subscriptionManager.cleanupAll();
384
- return;
385
- }
386
- for (const unsubscribe of this.graphqlSubscriptions.values()) {
387
- unsubscribe();
388
- }
389
- this.graphqlSubscriptions.clear();
390
- }
391
164
  fetchSyncBlockSourceInfoBySourceAri(sourceAri, hasAccess = true) {
392
165
  try {
393
166
  if (!this.dataProvider) {
@@ -396,11 +169,11 @@ export class ReferenceSyncBlockStoreManager {
396
169
  const sourceInfo = this.dataProvider.fetchSyncBlockSourceInfo(undefined, sourceAri, undefined, hasAccess);
397
170
  return sourceInfo;
398
171
  } catch (error) {
399
- var _this$fireAnalyticsEv7;
172
+ var _this$fireAnalyticsEv;
400
173
  logException(error, {
401
174
  location: 'editor-synced-block-provider/referenceSyncBlockStoreManager/fetchSyncBlockSourceInfoBySourceAri'
402
175
  });
403
- (_this$fireAnalyticsEv7 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv7 === void 0 ? void 0 : _this$fireAnalyticsEv7.call(this, getSourceInfoErrorPayload(error.message));
176
+ (_this$fireAnalyticsEv = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv === void 0 ? void 0 : _this$fireAnalyticsEv.call(this, getSourceInfoErrorPayload(error.message));
404
177
  return Promise.resolve(undefined);
405
178
  }
406
179
  }
@@ -439,42 +212,42 @@ export class ReferenceSyncBlockStoreManager {
439
212
  });
440
213
  }
441
214
  if (!sourceAri || !product || !blockInstanceId) {
442
- var _this$fireAnalyticsEv8;
443
- (_this$fireAnalyticsEv8 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv8 === void 0 ? void 0 : _this$fireAnalyticsEv8.call(this, getSourceInfoErrorPayload('SourceAri, product or blockInstanceId missing', resourceId));
215
+ var _this$fireAnalyticsEv2;
216
+ (_this$fireAnalyticsEv2 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv2 === void 0 ? void 0 : _this$fireAnalyticsEv2.call(this, getSourceInfoErrorPayload('SourceAri, product or blockInstanceId missing', resourceId));
444
217
  return Promise.resolve(undefined);
445
218
  }
446
219
  (_this$fetchSourceInfo = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo === void 0 ? void 0 : _this$fetchSourceInfo.start({});
447
220
  const sourceInfoPromise = this.dataProvider.fetchSyncBlockSourceInfo(blockInstanceId, sourceAri, product, true // hasAccess
448
221
  ).then(sourceInfo => {
449
222
  if (!sourceInfo) {
450
- var _this$fetchSourceInfo2, _this$fireAnalyticsEv9;
223
+ var _this$fetchSourceInfo2, _this$fireAnalyticsEv3;
451
224
  (_this$fetchSourceInfo2 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo2 === void 0 ? void 0 : _this$fetchSourceInfo2.failure({
452
225
  reason: 'No source info returned'
453
226
  });
454
- (_this$fireAnalyticsEv9 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv9 === void 0 ? void 0 : _this$fireAnalyticsEv9.call(this, getSourceInfoErrorPayload('No source info returned', resourceId));
227
+ (_this$fireAnalyticsEv3 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv3 === void 0 ? void 0 : _this$fireAnalyticsEv3.call(this, getSourceInfoErrorPayload('No source info returned', resourceId));
455
228
  return undefined;
456
229
  }
457
230
  this.updateCacheWithSourceInfo(resourceId, sourceInfo);
458
231
  if (sourceInfo.title) {
459
- this.updateSourceTitleSubscriptions(resourceId, sourceInfo.title);
232
+ this._subscriptionManager.updateSourceTitleSubscriptions(resourceId, sourceInfo.title);
460
233
  }
461
234
  if (sourceInfo.title && sourceInfo.url) {
462
235
  var _this$fetchSourceInfo3;
463
236
  (_this$fetchSourceInfo3 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo3 === void 0 ? void 0 : _this$fetchSourceInfo3.success();
464
237
  } else {
465
- var _this$fetchSourceInfo4, _this$fireAnalyticsEv0;
238
+ var _this$fetchSourceInfo4, _this$fireAnalyticsEv4;
466
239
  (_this$fetchSourceInfo4 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo4 === void 0 ? void 0 : _this$fetchSourceInfo4.failure({
467
240
  reason: 'Missing title or url'
468
241
  });
469
- (_this$fireAnalyticsEv0 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv0 === void 0 ? void 0 : _this$fireAnalyticsEv0.call(this, getSourceInfoErrorPayload('Missing title or url', resourceId));
242
+ (_this$fireAnalyticsEv4 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv4 === void 0 ? void 0 : _this$fireAnalyticsEv4.call(this, getSourceInfoErrorPayload('Missing title or url', resourceId));
470
243
  }
471
244
  return sourceInfo;
472
245
  }).catch(error => {
473
- var _this$fetchSourceInfo5, _this$fireAnalyticsEv1;
246
+ var _this$fetchSourceInfo5, _this$fireAnalyticsEv5;
474
247
  (_this$fetchSourceInfo5 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo5 === void 0 ? void 0 : _this$fetchSourceInfo5.failure({
475
248
  reason: error.message
476
249
  });
477
- (_this$fireAnalyticsEv1 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv1 === void 0 ? void 0 : _this$fireAnalyticsEv1.call(this, getSourceInfoErrorPayload(error.message, resourceId));
250
+ (_this$fireAnalyticsEv5 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv5 === void 0 ? void 0 : _this$fireAnalyticsEv5.call(this, getSourceInfoErrorPayload(error.message, resourceId));
478
251
  return undefined;
479
252
  }).finally(() => {
480
253
  this.syncBlockSourceInfoRequests.delete(resourceId);
@@ -482,11 +255,11 @@ export class ReferenceSyncBlockStoreManager {
482
255
  this.syncBlockSourceInfoRequests.set(resourceId, sourceInfoPromise);
483
256
  return sourceInfoPromise;
484
257
  } catch (error) {
485
- var _this$fireAnalyticsEv10;
258
+ var _this$fireAnalyticsEv6;
486
259
  logException(error, {
487
260
  location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
488
261
  });
489
- (_this$fireAnalyticsEv10 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv10 === void 0 ? void 0 : _this$fireAnalyticsEv10.call(this, getSourceInfoErrorPayload(error.message, resourceId));
262
+ (_this$fireAnalyticsEv6 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv6 === void 0 ? void 0 : _this$fireAnalyticsEv6.call(this, getSourceInfoErrorPayload(error.message, resourceId));
490
263
  }
491
264
  return Promise.resolve(undefined);
492
265
  }
@@ -535,7 +308,7 @@ export class ReferenceSyncBlockStoreManager {
535
308
  reason: `Prefetch promise rejected: ${error.message}`
536
309
  });
537
310
  } finally {
538
- // Clean up in-flight markers so subsequent fetches (e.g. refreshSubscriptions) are not blocked
311
+ // Clean up in-flight markers so subsequent fetches are not blocked
539
312
  prefetchedData.resourceIds.forEach(resourceId => {
540
313
  this.syncBlockFetchDataRequests.delete(resourceId);
541
314
  });
@@ -612,9 +385,9 @@ export class ReferenceSyncBlockStoreManager {
612
385
  data.forEach(syncBlockInstance => {
613
386
  var _resolvedSyncBlockIns;
614
387
  if (!syncBlockInstance.resourceId) {
615
- var _syncBlockInstance$er3, _syncBlockInstance$er4, _this$fireAnalyticsEv11;
616
- const 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';
617
- (_this$fireAnalyticsEv11 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv11 === void 0 ? void 0 : _this$fireAnalyticsEv11.call(this, fetchErrorPayload(payload));
388
+ var _syncBlockInstance$er, _syncBlockInstance$er2, _this$fireAnalyticsEv7;
389
+ const payload = ((_syncBlockInstance$er = syncBlockInstance.error) === null || _syncBlockInstance$er === void 0 ? void 0 : _syncBlockInstance$er.reason) || ((_syncBlockInstance$er2 = syncBlockInstance.error) === null || _syncBlockInstance$er2 === void 0 ? void 0 : _syncBlockInstance$er2.type) || 'Returned sync block instance does not have resource id';
390
+ (_this$fireAnalyticsEv7 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv7 === void 0 ? void 0 : _this$fireAnalyticsEv7.call(this, fetchErrorPayload(payload));
618
391
  return;
619
392
  }
620
393
  const existingSyncBlock = this.getFromCache(syncBlockInstance.resourceId);
@@ -632,8 +405,8 @@ export class ReferenceSyncBlockStoreManager {
632
405
  this.newlyAddedSyncBlocks.delete(syncBlockInstance.resourceId);
633
406
  }
634
407
  if (syncBlockInstance.error) {
635
- var _this$fireAnalyticsEv12;
636
- (_this$fireAnalyticsEv12 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv12 === void 0 ? void 0 : _this$fireAnalyticsEv12.call(this, fetchErrorPayload(syncBlockInstance.error.reason || syncBlockInstance.error.type, syncBlockInstance.resourceId));
408
+ var _this$fireAnalyticsEv8;
409
+ (_this$fireAnalyticsEv8 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv8 === void 0 ? void 0 : _this$fireAnalyticsEv8.call(this, fetchErrorPayload(syncBlockInstance.error.reason || syncBlockInstance.error.type, syncBlockInstance.resourceId));
637
410
  if (syncBlockInstance.error.type === SyncBlockError.NotFound || syncBlockInstance.error.type === SyncBlockError.Forbidden) {
638
411
  hasExpectedError = true;
639
412
  } else if (syncBlockInstance.error) {
@@ -641,11 +414,11 @@ export class ReferenceSyncBlockStoreManager {
641
414
  }
642
415
  return;
643
416
  }
644
- const callbacks = this.subscriptions.get(syncBlockInstance.resourceId);
417
+ const callbacks = this._subscriptionManager.getSubscriptions().get(syncBlockInstance.resourceId);
645
418
  const localIds = callbacks ? Object.keys(callbacks) : [];
646
419
  localIds.forEach(localId => {
647
- var _this$fireAnalyticsEv13, _syncBlockInstance$da2;
648
- (_this$fireAnalyticsEv13 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv13 === void 0 ? void 0 : _this$fireAnalyticsEv13.call(this, fetchSuccessPayload(syncBlockInstance.resourceId, localId, (_syncBlockInstance$da2 = syncBlockInstance.data) === null || _syncBlockInstance$da2 === void 0 ? void 0 : _syncBlockInstance$da2.product));
420
+ var _this$fireAnalyticsEv9, _syncBlockInstance$da;
421
+ (_this$fireAnalyticsEv9 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv9 === void 0 ? void 0 : _this$fireAnalyticsEv9.call(this, fetchSuccessPayload(syncBlockInstance.resourceId, localId, (_syncBlockInstance$da = syncBlockInstance.data) === null || _syncBlockInstance$da === void 0 ? void 0 : _syncBlockInstance$da.product));
649
422
  });
650
423
  this.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
651
424
  });
@@ -673,56 +446,29 @@ export class ReferenceSyncBlockStoreManager {
673
446
  resourceId
674
447
  } = syncBlock;
675
448
  if (resourceId) {
676
- var _this$dataProvider4;
677
- (_this$dataProvider4 = this.dataProvider) === null || _this$dataProvider4 === void 0 ? void 0 : _this$dataProvider4.updateCache({
449
+ var _this$dataProvider3;
450
+ (_this$dataProvider3 = this.dataProvider) === null || _this$dataProvider3 === void 0 ? void 0 : _this$dataProvider3.updateCache({
678
451
  [resourceId]: syncBlock
679
452
  }, {
680
453
  strategy: 'merge',
681
454
  source: 'network'
682
455
  });
683
- const callbacks = this.subscriptions.get(resourceId);
684
- if (callbacks) {
685
- Object.values(callbacks).forEach(callback => {
686
- callback(syncBlock);
687
- });
688
- }
456
+ this._subscriptionManager.notifySubscriptionCallbacks(resourceId, syncBlock);
689
457
  this.updateSessionCache(resourceId);
690
458
  }
691
459
  }
692
- updateSourceTitleSubscriptions(resourceId, title) {
693
- const callbacks = this.titleSubscriptions.get(resourceId);
694
- if (callbacks) {
695
- Object.values(callbacks).forEach(callback => {
696
- callback(title);
697
- });
698
- }
699
- }
700
460
  getFromCache(resourceId) {
701
- var _this$dataProvider5, _this$dataProvider5$g;
461
+ var _this$dataProvider4, _this$dataProvider4$g;
702
462
  const syncBlockNode = createSyncBlockNode('', resourceId);
703
- return (_this$dataProvider5 = this.dataProvider) === null || _this$dataProvider5 === void 0 ? void 0 : (_this$dataProvider5$g = _this$dataProvider5.getNodeDataFromCache(syncBlockNode)) === null || _this$dataProvider5$g === void 0 ? void 0 : _this$dataProvider5$g.data;
463
+ return (_this$dataProvider4 = this.dataProvider) === null || _this$dataProvider4 === void 0 ? void 0 : (_this$dataProvider4$g = _this$dataProvider4.getNodeDataFromCache(syncBlockNode)) === null || _this$dataProvider4$g === void 0 ? void 0 : _this$dataProvider4$g.data;
704
464
  }
705
465
  deleteFromCache(resourceId) {
706
- var _this$dataProvider6;
707
- (_this$dataProvider6 = this.dataProvider) === null || _this$dataProvider6 === void 0 ? void 0 : _this$dataProvider6.removeFromCache([resourceId]);
708
- if (this._providerFactoryManager && fg('platform_synced_block_patch_5')) {
709
- this._providerFactoryManager.deleteFactory(resourceId);
710
- } else {
711
- this.providerFactories.delete(resourceId);
712
- }
466
+ var _this$dataProvider5;
467
+ (_this$dataProvider5 = this.dataProvider) === null || _this$dataProvider5 === void 0 ? void 0 : _this$dataProvider5.removeFromCache([resourceId]);
468
+ this._providerFactoryManager.deleteFactory(resourceId);
713
469
  }
714
470
  debouncedBatchedFetchSyncBlocks(resourceId) {
715
- if (this._batchFetcher && fg('platform_synced_block_patch_5')) {
716
- this._batchFetcher.queueFetch(resourceId);
717
- return;
718
- }
719
- // Only add to pending requests if there are active subscriptions for this resource
720
- if (this.subscriptions.has(resourceId) && Object.keys(this.subscriptions.get(resourceId) || {}).length > 0) {
721
- this.pendingFetchRequests.add(resourceId);
722
- this.scheduledBatchFetch();
723
- } else {
724
- this.pendingFetchRequests.delete(resourceId);
725
- }
471
+ this._batchFetcher.queueFetch(resourceId);
726
472
  }
727
473
  setSSRDataInSessionCache(resourceIds) {
728
474
  if (!resourceIds || resourceIds.length === 0) {
@@ -733,114 +479,10 @@ export class ReferenceSyncBlockStoreManager {
733
479
  });
734
480
  }
735
481
  subscribeToSyncBlock(resourceId, localId, callback) {
736
- var _this$dataProvider7, _this$dataProvider7$g;
737
- // Cancel any pending cache deletion for this resourceId.
738
- // This handles the case where a block is moved - the old component unmounts
739
- // (scheduling deletion) but the new component mounts and subscribes before
740
- // the deletion timeout fires.
741
- const pendingDeletion = this.pendingCacheDeletions.get(resourceId);
742
- if (pendingDeletion) {
743
- clearTimeout(pendingDeletion);
744
- this.pendingCacheDeletions.delete(resourceId);
745
- }
746
-
747
- // add to subscriptions map
748
- const resourceSubscriptions = this.subscriptions.get(resourceId) || {};
749
- const isNewResourceSubscription = Object.keys(resourceSubscriptions).length === 0;
750
- this.subscriptions.set(resourceId, {
751
- ...resourceSubscriptions,
752
- [localId]: callback
753
- });
754
-
755
- // New subscription means new reference synced block is added to the document
756
- this.isCacheDirty = true;
757
-
758
- // Notify listeners if this is a new resource subscription
759
- if (isNewResourceSubscription) {
760
- this.notifySubscriptionChangeListeners();
761
- }
762
- const syncBlockNode = createSyncBlockNode(localId, resourceId);
763
- const cachedData = (_this$dataProvider7 = this.dataProvider) === null || _this$dataProvider7 === void 0 ? void 0 : (_this$dataProvider7$g = _this$dataProvider7.getNodeDataFromCache(syncBlockNode)) === null || _this$dataProvider7$g === void 0 ? void 0 : _this$dataProvider7$g.data;
764
- if (cachedData) {
765
- callback(cachedData);
766
- } else {
767
- this.debouncedBatchedFetchSyncBlocks(resourceId);
768
- }
769
-
770
- // Set up GraphQL subscription if real-time subscriptions are enabled
771
- const useRealTime = this._subscriptionManager && fg('platform_synced_block_patch_5') ? this._subscriptionManager.shouldUseRealTime() : this.useRealTimeSubscriptions;
772
- if (useRealTime) {
773
- this.setupGraphQLSubscription(resourceId);
774
- }
775
- return () => {
776
- const resourceSubscriptions = this.subscriptions.get(resourceId);
777
- if (resourceSubscriptions) {
778
- // Unsubscription means a reference synced block is removed from the document
779
- this.isCacheDirty = true;
780
- delete resourceSubscriptions[localId];
781
- if (Object.keys(resourceSubscriptions).length === 0) {
782
- this.subscriptions.delete(resourceId);
783
-
784
- // Clean up GraphQL subscription when no more local subscribers
785
- this.cleanupGraphQLSubscription(resourceId);
786
-
787
- // Notify listeners that subscription was removed
788
- this.notifySubscriptionChangeListeners();
789
-
790
- // Delay cache deletion to handle block moves (unmount/remount).
791
- // When a block is moved, the old component unmounts before the new one mounts.
792
- // By delaying deletion, we give the new component time to subscribe and
793
- // cancel this pending deletion, preserving the cached data.
794
- // TODO: EDITOR-4152 - Rework this logic
795
- const deletionTimeout = setTimeout(() => {
796
- // Only delete if still no subscribers (wasn't re-subscribed)
797
- if (!this.subscriptions.has(resourceId)) {
798
- this.deleteFromCache(resourceId);
799
- }
800
- this.pendingCacheDeletions.delete(resourceId);
801
- }, 1000);
802
- this.pendingCacheDeletions.set(resourceId, deletionTimeout);
803
- } else {
804
- this.subscriptions.set(resourceId, resourceSubscriptions);
805
- }
806
- }
807
- };
482
+ return this._subscriptionManager.subscribeToSyncBlock(resourceId, localId, callback);
808
483
  }
809
484
  subscribeToSourceTitle(node, callback) {
810
- var _cachedData$data;
811
- // check node is a sync block, as we only support sync block subscriptions
812
- if (node.type.name !== 'syncBlock') {
813
- return () => {};
814
- }
815
- const {
816
- resourceId,
817
- localId
818
- } = node.attrs;
819
- if (!localId || !resourceId) {
820
- return () => {};
821
- }
822
- const cachedData = this.getFromCache(resourceId);
823
- if (cachedData !== null && cachedData !== void 0 && (_cachedData$data = cachedData.data) !== null && _cachedData$data !== void 0 && _cachedData$data.sourceTitle) {
824
- callback(cachedData.data.sourceTitle);
825
- }
826
-
827
- // add to subscriptions map
828
- const resourceSubscriptions = this.titleSubscriptions.get(resourceId) || {};
829
- this.titleSubscriptions.set(resourceId, {
830
- ...resourceSubscriptions,
831
- [localId]: callback
832
- });
833
- return () => {
834
- const resourceSubscriptions = this.titleSubscriptions.get(resourceId);
835
- if (resourceSubscriptions) {
836
- delete resourceSubscriptions[localId];
837
- if (Object.keys(resourceSubscriptions).length === 0) {
838
- this.titleSubscriptions.delete(resourceId);
839
- } else {
840
- this.titleSubscriptions.set(resourceId, resourceSubscriptions);
841
- }
842
- }
843
- };
485
+ return this._subscriptionManager.subscribeToSourceTitle(node, callback);
844
486
  }
845
487
  subscribe(node, callback) {
846
488
  try {
@@ -855,13 +497,13 @@ export class ReferenceSyncBlockStoreManager {
855
497
  if (!localId || !resourceId) {
856
498
  throw new Error('Missing local id or resource id');
857
499
  }
858
- return this.subscribeToSyncBlock(resourceId, localId, callback);
500
+ return this._subscriptionManager.subscribeToSyncBlock(resourceId, localId, callback);
859
501
  } catch (error) {
860
- var _this$fireAnalyticsEv14;
502
+ var _this$fireAnalyticsEv0;
861
503
  logException(error, {
862
504
  location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
863
505
  });
864
- (_this$fireAnalyticsEv14 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv14 === void 0 ? void 0 : _this$fireAnalyticsEv14.call(this, fetchErrorPayload(error.message));
506
+ (_this$fireAnalyticsEv0 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv0 === void 0 ? void 0 : _this$fireAnalyticsEv0.call(this, fetchErrorPayload(error.message));
865
507
  return () => {};
866
508
  }
867
509
  }
@@ -880,150 +522,10 @@ export class ReferenceSyncBlockStoreManager {
880
522
  return (_syncBlock$data = syncBlock.data) === null || _syncBlock$data === void 0 ? void 0 : _syncBlock$data.sourceURL;
881
523
  }
882
524
  getProviderFactory(resourceId) {
883
- if (this._providerFactoryManager && fg('platform_synced_block_patch_5')) {
884
- return this._providerFactoryManager.getProviderFactory(resourceId);
885
- }
886
- if (!this.dataProvider) {
887
- var _this$fireAnalyticsEv15;
888
- const error = new Error('Data provider not set');
889
- logException(error, {
890
- location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
891
- });
892
- (_this$fireAnalyticsEv15 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv15 === void 0 ? void 0 : _this$fireAnalyticsEv15.call(this, fetchErrorPayload(error.message));
893
- return undefined;
894
- }
895
- const {
896
- parentDataProviders,
897
- providerCreator
898
- } = this.dataProvider.getSyncedBlockRendererProviderOptions();
899
- let providerFactory = this.providerFactories.get(resourceId);
900
- if (!providerFactory) {
901
- providerFactory = ProviderFactory.create({
902
- mentionProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.mentionProvider,
903
- profilecardProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.profilecardProvider,
904
- taskDecisionProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.taskDecisionProvider
905
- });
906
- this.providerFactories.set(resourceId, providerFactory);
907
- } else {
908
- if (parentDataProviders !== null && parentDataProviders !== void 0 && parentDataProviders.mentionProvider) {
909
- providerFactory.setProvider('mentionProvider', parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.mentionProvider);
910
- }
911
- if (parentDataProviders !== null && parentDataProviders !== void 0 && parentDataProviders.profilecardProvider) {
912
- providerFactory.setProvider('profilecardProvider', parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.profilecardProvider);
913
- }
914
- if (parentDataProviders !== null && parentDataProviders !== void 0 && parentDataProviders.taskDecisionProvider) {
915
- providerFactory.setProvider('taskDecisionProvider', parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.taskDecisionProvider);
916
- }
917
- }
918
- if (providerCreator) {
919
- try {
920
- this.retrieveDynamicProviders(resourceId, providerFactory, providerCreator);
921
- } catch (error) {
922
- var _this$fireAnalyticsEv16;
923
- logException(error, {
924
- location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
925
- });
926
- (_this$fireAnalyticsEv16 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv16 === void 0 ? void 0 : _this$fireAnalyticsEv16.call(this, fetchErrorPayload(error.message, resourceId));
927
- }
928
- }
929
- return providerFactory;
525
+ return this._providerFactoryManager.getProviderFactory(resourceId);
930
526
  }
931
527
  getSSRProviders(resourceId) {
932
- if (this._providerFactoryManager && fg('platform_synced_block_patch_5')) {
933
- return this._providerFactoryManager.getSSRProviders(resourceId);
934
- }
935
- if (!this.dataProvider) {
936
- return null;
937
- }
938
- const {
939
- providerCreator
940
- } = this.dataProvider.getSyncedBlockRendererProviderOptions();
941
- if (!(providerCreator !== null && providerCreator !== void 0 && providerCreator.createSSRMediaProvider)) {
942
- return null;
943
- }
944
- const parsedResourceId = parseResourceId(resourceId);
945
- if (!parsedResourceId) {
946
- return null;
947
- }
948
- const {
949
- contentId,
950
- product: contentProduct
951
- } = parsedResourceId;
952
- try {
953
- const mediaProvider = providerCreator.createSSRMediaProvider({
954
- contentId,
955
- contentProduct
956
- });
957
- if (mediaProvider) {
958
- return {
959
- media: mediaProvider
960
- };
961
- }
962
- } catch (error) {
963
- logException(error, {
964
- location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
965
- });
966
- }
967
- return null;
968
- }
969
- retrieveDynamicProviders(resourceId, providerFactory, providerCreator) {
970
- var _syncBlock$data2, _syncBlock$data3;
971
- if (!this.dataProvider) {
972
- throw new Error('Data provider not set');
973
- }
974
- const hasMediaProvider = providerFactory.hasProvider('mediaProvider');
975
- const hasEmojiProvider = providerFactory.hasProvider('emojiProvider');
976
- const hasCardProvider = providerFactory.hasProvider('cardProvider');
977
- if (hasMediaProvider && hasEmojiProvider && hasCardProvider) {
978
- return;
979
- }
980
- const syncBlock = this.getFromCache(resourceId);
981
- if (!(syncBlock !== null && syncBlock !== void 0 && syncBlock.data)) {
982
- return;
983
- }
984
- if (!syncBlock.data.sourceAri || !syncBlock.data.product) {
985
- var _this$fireAnalyticsEv17;
986
- (_this$fireAnalyticsEv17 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv17 === void 0 ? void 0 : _this$fireAnalyticsEv17.call(this, fetchErrorPayload('Sync block source ari or product not found'));
987
- return;
988
- }
989
- const 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);
990
- if (!parentInfo) {
991
- throw new Error('Unable to retrieve sync block parent info');
992
- }
993
- const {
994
- contentId,
995
- contentProduct
996
- } = parentInfo;
997
- if (!hasMediaProvider) {
998
- if (providerCreator.createMediaProvider && contentId && contentProduct) {
999
- const mediaProvider = providerCreator.createMediaProvider({
1000
- contentProduct,
1001
- contentId
1002
- });
1003
- if (mediaProvider) {
1004
- providerFactory.setProvider('mediaProvider', mediaProvider);
1005
- }
1006
- }
1007
- }
1008
- if (!hasEmojiProvider) {
1009
- if (providerCreator.createEmojiProvider && contentId && contentProduct) {
1010
- const emojiProvider = providerCreator.createEmojiProvider({
1011
- contentProduct,
1012
- contentId
1013
- });
1014
- if (emojiProvider) {
1015
- providerFactory.setProvider('emojiProvider', emojiProvider);
1016
- }
1017
- }
1018
- }
1019
- if (!hasCardProvider) {
1020
- if (providerCreator.createSmartLinkProvider) {
1021
- const smartLinkProvider = providerCreator.createSmartLinkProvider();
1022
- if (smartLinkProvider) {
1023
- providerFactory.setProvider('cardProvider', smartLinkProvider);
1024
- }
1025
- }
1026
- }
528
+ return this._providerFactoryManager.getSSRProviders(resourceId);
1027
529
  }
1028
530
 
1029
531
  /**
@@ -1059,7 +561,7 @@ export class ReferenceSyncBlockStoreManager {
1059
561
  const blocks = [];
1060
562
 
1061
563
  // First, build the complete subscription structure
1062
- for (const [resourceId, callbacks] of this.subscriptions.entries()) {
564
+ for (const [resourceId, callbacks] of this._subscriptionManager.getSubscriptions().entries()) {
1063
565
  syncedBlocksToFlush[resourceId] = {};
1064
566
  Object.keys(callbacks).forEach(localId => {
1065
567
  blocks.push({
@@ -1088,15 +590,15 @@ export class ReferenceSyncBlockStoreManager {
1088
590
  (_this$saveExperience = this.saveExperience) === null || _this$saveExperience === void 0 ? void 0 : _this$saveExperience.start();
1089
591
  const updateResult = await this.dataProvider.updateReferenceData(blocks);
1090
592
  if (!updateResult.success) {
1091
- var _this$saveExperience2, _this$fireAnalyticsEv18;
593
+ var _this$saveExperience2, _this$fireAnalyticsEv1;
1092
594
  success = false;
1093
595
  (_this$saveExperience2 = this.saveExperience) === null || _this$saveExperience2 === void 0 ? void 0 : _this$saveExperience2.failure({
1094
596
  reason: updateResult.error || 'Failed to update reference synced blocks on the document'
1095
597
  });
1096
- (_this$fireAnalyticsEv18 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv18 === void 0 ? void 0 : _this$fireAnalyticsEv18.call(this, updateReferenceErrorPayload(updateResult.error || 'Failed to update reference synced blocks on the document'));
598
+ (_this$fireAnalyticsEv1 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv1 === void 0 ? void 0 : _this$fireAnalyticsEv1.call(this, updateReferenceErrorPayload(updateResult.error || 'Failed to update reference synced blocks on the document'));
1097
599
  }
1098
600
  } catch (error) {
1099
- var _this$saveExperience3, _this$fireAnalyticsEv19;
601
+ var _this$saveExperience3, _this$fireAnalyticsEv10;
1100
602
  success = false;
1101
603
  logException(error, {
1102
604
  location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
@@ -1104,7 +606,7 @@ export class ReferenceSyncBlockStoreManager {
1104
606
  (_this$saveExperience3 = this.saveExperience) === null || _this$saveExperience3 === void 0 ? void 0 : _this$saveExperience3.failure({
1105
607
  reason: error.message
1106
608
  });
1107
- (_this$fireAnalyticsEv19 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv19 === void 0 ? void 0 : _this$fireAnalyticsEv19.call(this, updateReferenceErrorPayload(error.message));
609
+ (_this$fireAnalyticsEv10 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv10 === void 0 ? void 0 : _this$fireAnalyticsEv10.call(this, updateReferenceErrorPayload(error.message));
1108
610
  } finally {
1109
611
  if (!success) {
1110
612
  // set isCacheDirty back to true for cases where it failed to update the reference synced blocks on the BE
@@ -1132,36 +634,19 @@ export class ReferenceSyncBlockStoreManager {
1132
634
  return success;
1133
635
  }
1134
636
  destroy() {
1135
- var _this$dataProvider8, _this$saveExperience5, _this$fetchExperience0, _this$fetchSourceInfo6;
637
+ var _this$dataProvider6, _this$saveExperience5, _this$fetchExperience0, _this$fetchSourceInfo6;
1136
638
  // Cancel any queued flush to prevent it from running after destroy
1137
639
  if (this.queuedFlushTimeout) {
1138
640
  clearTimeout(this.queuedFlushTimeout);
1139
641
  this.queuedFlushTimeout = undefined;
1140
642
  }
1141
- if (fg('platform_synced_block_patch_5')) {
1142
- var _this$_subscriptionMa, _this$_providerFactor, _this$_batchFetcher;
1143
- (_this$_subscriptionMa = this._subscriptionManager) === null || _this$_subscriptionMa === void 0 ? void 0 : _this$_subscriptionMa.destroy();
1144
- (_this$_providerFactor = this._providerFactoryManager) === null || _this$_providerFactor === void 0 ? void 0 : _this$_providerFactor.destroy();
1145
- (_this$_batchFetcher = this._batchFetcher) === null || _this$_batchFetcher === void 0 ? void 0 : _this$_batchFetcher.destroy();
1146
- }
1147
-
1148
- // Clean up all GraphQL subscriptions first
1149
- this.cleanupAllGraphQLSubscriptions();
1150
- (_this$dataProvider8 = this.dataProvider) === null || _this$dataProvider8 === void 0 ? void 0 : _this$dataProvider8.resetCache();
1151
- this.scheduledBatchFetch.cancel();
1152
- this.pendingFetchRequests.clear();
643
+ this._subscriptionManager.destroy();
644
+ this._providerFactoryManager.destroy();
645
+ this._batchFetcher.destroy();
646
+ (_this$dataProvider6 = this.dataProvider) === null || _this$dataProvider6 === void 0 ? void 0 : _this$dataProvider6.resetCache();
1153
647
  this.dataProvider = undefined;
1154
- this.subscriptions.clear();
1155
- this.titleSubscriptions.clear();
1156
648
  this.syncBlockFetchDataRequests.clear();
1157
649
  this.syncBlockSourceInfoRequests.clear();
1158
- this.isRefreshingSubscriptions = false;
1159
- this.useRealTimeSubscriptions = false;
1160
- this.subscriptionChangeListeners.clear();
1161
- this.providerFactories.forEach(providerFactory => {
1162
- providerFactory.destroy();
1163
- });
1164
- this.providerFactories.clear();
1165
650
  (_this$saveExperience5 = this.saveExperience) === null || _this$saveExperience5 === void 0 ? void 0 : _this$saveExperience5.abort({
1166
651
  reason: 'editorDestroyed'
1167
652
  });
@@ -1172,8 +657,6 @@ export class ReferenceSyncBlockStoreManager {
1172
657
  reason: 'editorDestroyed'
1173
658
  });
1174
659
  this.fireAnalyticsEvent = undefined;
1175
- if (fg('platform_synced_block_patch_5')) {
1176
- syncBlockInMemorySessionCache.clear();
1177
- }
660
+ syncBlockInMemorySessionCache.clear();
1178
661
  }
1179
662
  }