@atlaskit/editor-synced-block-provider 3.31.0 → 3.31.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.
Files changed (32) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +117 -9
  3. package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +16 -0
  4. package/dist/cjs/store-manager/syncBlockBatchFetcher.js +76 -0
  5. package/dist/cjs/store-manager/syncBlockInMemorySessionCache.js +26 -0
  6. package/dist/cjs/store-manager/syncBlockProviderFactoryManager.js +175 -0
  7. package/dist/cjs/store-manager/syncBlockSubscriptionManager.js +198 -0
  8. package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +93 -9
  9. package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +12 -0
  10. package/dist/es2019/store-manager/syncBlockBatchFetcher.js +56 -0
  11. package/dist/es2019/store-manager/syncBlockInMemorySessionCache.js +24 -0
  12. package/dist/es2019/store-manager/syncBlockProviderFactoryManager.js +158 -0
  13. package/dist/es2019/store-manager/syncBlockSubscriptionManager.js +136 -0
  14. package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +117 -9
  15. package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +16 -0
  16. package/dist/esm/store-manager/syncBlockBatchFetcher.js +69 -0
  17. package/dist/esm/store-manager/syncBlockInMemorySessionCache.js +26 -0
  18. package/dist/esm/store-manager/syncBlockProviderFactoryManager.js +168 -0
  19. package/dist/esm/store-manager/syncBlockSubscriptionManager.js +191 -0
  20. package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +3 -0
  21. package/dist/types/store-manager/sourceSyncBlockStoreManager.d.ts +2 -0
  22. package/dist/types/store-manager/syncBlockBatchFetcher.d.ts +25 -0
  23. package/dist/types/store-manager/syncBlockInMemorySessionCache.d.ts +18 -0
  24. package/dist/types/store-manager/syncBlockProviderFactoryManager.d.ts +25 -0
  25. package/dist/types/store-manager/syncBlockSubscriptionManager.d.ts +38 -0
  26. package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +3 -0
  27. package/dist/types-ts4.5/store-manager/sourceSyncBlockStoreManager.d.ts +2 -0
  28. package/dist/types-ts4.5/store-manager/syncBlockBatchFetcher.d.ts +25 -0
  29. package/dist/types-ts4.5/store-manager/syncBlockInMemorySessionCache.d.ts +18 -0
  30. package/dist/types-ts4.5/store-manager/syncBlockProviderFactoryManager.d.ts +25 -0
  31. package/dist/types-ts4.5/store-manager/syncBlockSubscriptionManager.d.ts +38 -0
  32. package/package.json +5 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atlaskit/editor-synced-block-provider
2
2
 
3
+ ## 3.31.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`432dbdcd07917`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/432dbdcd07917) -
8
+ EDITOR-5500 add hasUnsavedBodiedSyncBlocks state to synced block plugin to allow confluence to
9
+ check whether changes have been saved yet before leaving the page
10
+
11
+ ## 3.31.1
12
+
13
+ ### Patch Changes
14
+
15
+ - [`6424f86f6390a`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/6424f86f6390a) -
16
+ Improve Synced Blocks robustness
17
+ - Updated dependencies
18
+
3
19
  ## 3.31.0
4
20
 
5
21
  ### Minor Changes
@@ -22,7 +22,10 @@ var _experienceTracking = require("../utils/experienceTracking");
22
22
  var _resolveSyncBlockInstance = require("../utils/resolveSyncBlockInstance");
23
23
  var _resourceId = require("../utils/resourceId");
24
24
  var _utils = require("../utils/utils");
25
+ var _syncBlockBatchFetcher = require("./syncBlockBatchFetcher");
25
26
  var _syncBlockInMemorySessionCache = require("./syncBlockInMemorySessionCache");
27
+ var _syncBlockProviderFactoryManager = require("./syncBlockProviderFactoryManager");
28
+ var _syncBlockSubscriptionManager = require("./syncBlockSubscriptionManager");
26
29
  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; }
27
30
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
28
31
  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; } } }; }
@@ -85,6 +88,50 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
85
88
  this.graphqlSubscriptions = new Map();
86
89
  this.subscriptionChangeListeners = new Set();
87
90
  this.newlyAddedSyncBlocks = new Set();
91
+ if ((0, _platformFeatureFlags.fg)('platform_synced_block_patch_5')) {
92
+ this._subscriptionManager = new _syncBlockSubscriptionManager.SyncBlockSubscriptionManager({
93
+ getDataProvider: function getDataProvider() {
94
+ return _this.dataProvider;
95
+ },
96
+ getSubscriptions: function getSubscriptions() {
97
+ return _this.subscriptions;
98
+ },
99
+ getFromCache: function getFromCache(rid) {
100
+ return _this.getFromCache(rid);
101
+ },
102
+ updateCache: function updateCache(inst) {
103
+ return _this.updateCache(inst);
104
+ },
105
+ fetchSyncBlockSourceInfo: function fetchSyncBlockSourceInfo(rid) {
106
+ return _this.fetchSyncBlockSourceInfo(rid);
107
+ },
108
+ getFireAnalyticsEvent: function getFireAnalyticsEvent() {
109
+ return _this.fireAnalyticsEvent;
110
+ }
111
+ });
112
+ this._providerFactoryManager = new _syncBlockProviderFactoryManager.SyncBlockProviderFactoryManager({
113
+ getDataProvider: function getDataProvider() {
114
+ return _this.dataProvider;
115
+ },
116
+ getFromCache: function getFromCache(rid) {
117
+ return _this.getFromCache(rid);
118
+ },
119
+ getFireAnalyticsEvent: function getFireAnalyticsEvent() {
120
+ return _this.fireAnalyticsEvent;
121
+ }
122
+ });
123
+ this._batchFetcher = new _syncBlockBatchFetcher.SyncBlockBatchFetcher({
124
+ getSubscriptions: function getSubscriptions() {
125
+ return _this.subscriptions;
126
+ },
127
+ fetchSyncBlocksData: function fetchSyncBlocksData(nodes) {
128
+ return _this.fetchSyncBlocksData(nodes);
129
+ },
130
+ getFireAnalyticsEvent: function getFireAnalyticsEvent() {
131
+ return _this.fireAnalyticsEvent;
132
+ }
133
+ });
134
+ }
88
135
 
89
136
  // The provider might have SSR data cache already set, so we need to update the cache in session memory storage
90
137
  this.setSSRDataInSessionCache((_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.getNodeDataCacheKeys());
@@ -99,6 +146,10 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
99
146
  return (0, _createClass2.default)(ReferenceSyncBlockStoreManager, [{
100
147
  key: "setRealTimeSubscriptionsEnabled",
101
148
  value: function setRealTimeSubscriptionsEnabled(enabled) {
149
+ if (this._subscriptionManager && (0, _platformFeatureFlags.fg)('platform_synced_block_patch_5')) {
150
+ this._subscriptionManager.setRealTimeSubscriptionsEnabled(enabled);
151
+ return;
152
+ }
102
153
  if (this.useRealTimeSubscriptions === enabled) {
103
154
  return;
104
155
  }
@@ -118,6 +169,9 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
118
169
  }, {
119
170
  key: "isRealTimeSubscriptionsEnabled",
120
171
  value: function isRealTimeSubscriptionsEnabled() {
172
+ if (this._subscriptionManager && (0, _platformFeatureFlags.fg)('platform_synced_block_patch_5')) {
173
+ return this._subscriptionManager.isRealTimeSubscriptionsEnabled();
174
+ }
121
175
  return this.useRealTimeSubscriptions;
122
176
  }
123
177
 
@@ -128,6 +182,9 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
128
182
  }, {
129
183
  key: "getSubscribedResourceIds",
130
184
  value: function getSubscribedResourceIds() {
185
+ if (this._subscriptionManager && (0, _platformFeatureFlags.fg)('platform_synced_block_patch_5')) {
186
+ return this._subscriptionManager.getSubscribedResourceIds();
187
+ }
131
188
  return Array.from(this.subscriptions.keys());
132
189
  }
133
190
 
@@ -140,6 +197,9 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
140
197
  key: "onSubscriptionsChanged",
141
198
  value: function onSubscriptionsChanged(listener) {
142
199
  var _this2 = this;
200
+ if (this._subscriptionManager && (0, _platformFeatureFlags.fg)('platform_synced_block_patch_5')) {
201
+ return this._subscriptionManager.onSubscriptionsChanged(listener);
202
+ }
143
203
  this.subscriptionChangeListeners.add(listener);
144
204
  return function () {
145
205
  _this2.subscriptionChangeListeners.delete(listener);
@@ -153,6 +213,10 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
153
213
  key: "notifySubscriptionChangeListeners",
154
214
  value: function notifySubscriptionChangeListeners() {
155
215
  var _this3 = this;
216
+ if (this._subscriptionManager && (0, _platformFeatureFlags.fg)('platform_synced_block_patch_5')) {
217
+ this._subscriptionManager.notifySubscriptionChangeListeners();
218
+ return;
219
+ }
156
220
  this.subscriptionChangeListeners.forEach(function (listener) {
157
221
  try {
158
222
  listener();
@@ -174,6 +238,10 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
174
238
  }, {
175
239
  key: "handleSubscriptionUpdate",
176
240
  value: function handleSubscriptionUpdate(syncBlockInstance) {
241
+ if (this._subscriptionManager && (0, _platformFeatureFlags.fg)('platform_synced_block_patch_5')) {
242
+ this._subscriptionManager.handleSubscriptionUpdate(syncBlockInstance);
243
+ return;
244
+ }
177
245
  if (!syncBlockInstance.resourceId) {
178
246
  return;
179
247
  }
@@ -361,6 +429,11 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
361
429
  value: function setupGraphQLSubscription(resourceId) {
362
430
  var _this$dataProvider3,
363
431
  _this4 = this;
432
+ if (this._subscriptionManager && (0, _platformFeatureFlags.fg)('platform_synced_block_patch_5')) {
433
+ this._subscriptionManager.setupSubscription(resourceId);
434
+ return;
435
+ }
436
+
364
437
  // Don't set up duplicate subscriptions
365
438
  if (this.graphqlSubscriptions.has(resourceId)) {
366
439
  return;
@@ -422,6 +495,10 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
422
495
  }, {
423
496
  key: "cleanupGraphQLSubscription",
424
497
  value: function cleanupGraphQLSubscription(resourceId) {
498
+ if (this._subscriptionManager && (0, _platformFeatureFlags.fg)('platform_synced_block_patch_5')) {
499
+ this._subscriptionManager.cleanupSubscription(resourceId);
500
+ return;
501
+ }
425
502
  var unsubscribe = this.graphqlSubscriptions.get(resourceId);
426
503
  if (unsubscribe) {
427
504
  unsubscribe();
@@ -435,6 +512,10 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
435
512
  }, {
436
513
  key: "setupGraphQLSubscriptionsForAllBlocks",
437
514
  value: function setupGraphQLSubscriptionsForAllBlocks() {
515
+ if (this._subscriptionManager && (0, _platformFeatureFlags.fg)('platform_synced_block_patch_5')) {
516
+ this._subscriptionManager.setupSubscriptionsForAllBlocks();
517
+ return;
518
+ }
438
519
  var _iterator2 = _createForOfIteratorHelper(this.subscriptions.keys()),
439
520
  _step2;
440
521
  try {
@@ -455,6 +536,10 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
455
536
  }, {
456
537
  key: "cleanupAllGraphQLSubscriptions",
457
538
  value: function cleanupAllGraphQLSubscriptions() {
539
+ if (this._subscriptionManager && (0, _platformFeatureFlags.fg)('platform_synced_block_patch_5')) {
540
+ this._subscriptionManager.cleanupAll();
541
+ return;
542
+ }
458
543
  var _iterator3 = _createForOfIteratorHelper(this.graphqlSubscriptions.values()),
459
544
  _step3;
460
545
  try {
@@ -783,14 +868,13 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
783
868
  hasUnexpectedError = true;
784
869
  }
785
870
  return;
786
- } else {
787
- var callbacks = _this9.subscriptions.get(syncBlockInstance.resourceId);
788
- var localIds = callbacks ? Object.keys(callbacks) : [];
789
- localIds.forEach(function (localId) {
790
- var _this9$fireAnalyticsE4, _syncBlockInstance$da2;
791
- (_this9$fireAnalyticsE4 = _this9.fireAnalyticsEvent) === null || _this9$fireAnalyticsE4 === void 0 || _this9$fireAnalyticsE4.call(_this9, (0, _errorHandling.fetchSuccessPayload)(syncBlockInstance.resourceId, localId, (_syncBlockInstance$da2 = syncBlockInstance.data) === null || _syncBlockInstance$da2 === void 0 ? void 0 : _syncBlockInstance$da2.product));
792
- });
793
871
  }
872
+ var callbacks = _this9.subscriptions.get(syncBlockInstance.resourceId);
873
+ var localIds = callbacks ? Object.keys(callbacks) : [];
874
+ localIds.forEach(function (localId) {
875
+ var _this9$fireAnalyticsE4, _syncBlockInstance$da2;
876
+ (_this9$fireAnalyticsE4 = _this9.fireAnalyticsEvent) === null || _this9$fireAnalyticsE4 === void 0 || _this9$fireAnalyticsE4.call(_this9, (0, _errorHandling.fetchSuccessPayload)(syncBlockInstance.resourceId, localId, (_syncBlockInstance$da2 = syncBlockInstance.data) === null || _syncBlockInstance$da2 === void 0 ? void 0 : _syncBlockInstance$da2.product));
877
+ });
794
878
  _this9.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
795
879
  });
796
880
  return {
@@ -856,11 +940,19 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
856
940
  value: function deleteFromCache(resourceId) {
857
941
  var _this$dataProvider6;
858
942
  (_this$dataProvider6 = this.dataProvider) === null || _this$dataProvider6 === void 0 || _this$dataProvider6.removeFromCache([resourceId]);
859
- this.providerFactories.delete(resourceId);
943
+ if (this._providerFactoryManager && (0, _platformFeatureFlags.fg)('platform_synced_block_patch_5')) {
944
+ this._providerFactoryManager.deleteFactory(resourceId);
945
+ } else {
946
+ this.providerFactories.delete(resourceId);
947
+ }
860
948
  }
861
949
  }, {
862
950
  key: "debouncedBatchedFetchSyncBlocks",
863
951
  value: function debouncedBatchedFetchSyncBlocks(resourceId) {
952
+ if (this._batchFetcher && (0, _platformFeatureFlags.fg)('platform_synced_block_patch_5')) {
953
+ this._batchFetcher.queueFetch(resourceId);
954
+ return;
955
+ }
864
956
  // Only add to pending requests if there are active subscriptions for this resource
865
957
  if (this.subscriptions.has(resourceId) && Object.keys(this.subscriptions.get(resourceId) || {}).length > 0) {
866
958
  this.pendingFetchRequests.add(resourceId);
@@ -916,7 +1008,8 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
916
1008
  }
917
1009
 
918
1010
  // Set up GraphQL subscription if real-time subscriptions are enabled
919
- if (this.useRealTimeSubscriptions) {
1011
+ var useRealTime = this._subscriptionManager && (0, _platformFeatureFlags.fg)('platform_synced_block_patch_5') ? this._subscriptionManager.shouldUseRealTime() : this.useRealTimeSubscriptions;
1012
+ if (useRealTime) {
920
1013
  this.setupGraphQLSubscription(resourceId);
921
1014
  }
922
1015
  return function () {
@@ -1031,6 +1124,9 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
1031
1124
  }, {
1032
1125
  key: "getProviderFactory",
1033
1126
  value: function getProviderFactory(resourceId) {
1127
+ if (this._providerFactoryManager && (0, _platformFeatureFlags.fg)('platform_synced_block_patch_5')) {
1128
+ return this._providerFactoryManager.getProviderFactory(resourceId);
1129
+ }
1034
1130
  if (!this.dataProvider) {
1035
1131
  var _this$fireAnalyticsEv8;
1036
1132
  var error = new Error('Data provider not set');
@@ -1078,6 +1174,9 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
1078
1174
  }, {
1079
1175
  key: "getSSRProviders",
1080
1176
  value: function getSSRProviders(resourceId) {
1177
+ if (this._providerFactoryManager && (0, _platformFeatureFlags.fg)('platform_synced_block_patch_5')) {
1178
+ return this._providerFactoryManager.getSSRProviders(resourceId);
1179
+ }
1081
1180
  if (!this.dataProvider) {
1082
1181
  return null;
1083
1182
  }
@@ -1340,6 +1439,12 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
1340
1439
  clearTimeout(this.queuedFlushTimeout);
1341
1440
  this.queuedFlushTimeout = undefined;
1342
1441
  }
1442
+ if ((0, _platformFeatureFlags.fg)('platform_synced_block_patch_5')) {
1443
+ var _this$_subscriptionMa, _this$_providerFactor, _this$_batchFetcher;
1444
+ (_this$_subscriptionMa = this._subscriptionManager) === null || _this$_subscriptionMa === void 0 || _this$_subscriptionMa.destroy();
1445
+ (_this$_providerFactor = this._providerFactoryManager) === null || _this$_providerFactor === void 0 || _this$_providerFactor.destroy();
1446
+ (_this$_batchFetcher = this._batchFetcher) === null || _this$_batchFetcher === void 0 || _this$_batchFetcher.destroy();
1447
+ }
1343
1448
 
1344
1449
  // Clean up all GraphQL subscriptions first
1345
1450
  this.cleanupAllGraphQLSubscriptions();
@@ -1368,6 +1473,9 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
1368
1473
  reason: 'editorDestroyed'
1369
1474
  });
1370
1475
  this.fireAnalyticsEvent = undefined;
1476
+ if ((0, _platformFeatureFlags.fg)('platform_synced_block_patch_5')) {
1477
+ _syncBlockInMemorySessionCache.syncBlockInMemorySessionCache.clear();
1478
+ }
1371
1479
  }
1372
1480
  }]);
1373
1481
  }();
@@ -10,7 +10,9 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
10
10
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
11
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
12
12
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
+ var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
13
14
  var _monitoring = require("@atlaskit/editor-common/monitoring");
15
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
14
16
  var _types = require("../common/types");
15
17
  var _errorHandling = require("../utils/errorHandling");
16
18
  var _experienceTracking = require("../utils/experienceTracking");
@@ -26,6 +28,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
26
28
  function SourceSyncBlockStoreManager(dataProvider) {
27
29
  var _this = this;
28
30
  (0, _classCallCheck2.default)(this, SourceSyncBlockStoreManager);
31
+ (0, _defineProperty2.default)(this, "hasReceivedContentChange", false);
29
32
  (0, _defineProperty2.default)(this, "setPendingDeletion", function (Ids, value) {
30
33
  var syncBlock = _this.syncBlockCache.get(Ids.resourceId);
31
34
  if (syncBlock) {
@@ -69,6 +72,12 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
69
72
  throw new Error('Local ID or resource ID is not set');
70
73
  }
71
74
  var syncBlockData = (0, _utils.convertSyncBlockPMNodeToSyncBlockData)(syncBlockNode);
75
+ if ((0, _platformFeatureFlags.fg)('platform_synced_block_patch_5')) {
76
+ var cachedBlock = this.syncBlockCache.get(resourceId);
77
+ if (cachedBlock && !(0, _isEqual.default)(syncBlockData.content, cachedBlock.content)) {
78
+ this.hasReceivedContentChange = true;
79
+ }
80
+ }
72
81
  this.syncBlockCache.set(resourceId, _objectSpread(_objectSpread({}, syncBlockData), {}, {
73
82
  isDirty: true
74
83
  }));
@@ -197,6 +206,13 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
197
206
  }
198
207
  return flush;
199
208
  }())
209
+ }, {
210
+ key: "hasUnsavedChanges",
211
+ value: function hasUnsavedChanges() {
212
+ return this.hasReceivedContentChange && Array.from(this.syncBlockCache.values()).some(function (syncBlockData) {
213
+ return syncBlockData.isDirty;
214
+ });
215
+ }
200
216
  }, {
201
217
  key: "isPendingCreation",
202
218
  value: function isPendingCreation(resourceId) {
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.SyncBlockBatchFetcher = void 0;
8
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+ var _rafSchd = _interopRequireDefault(require("raf-schd"));
12
+ var _monitoring = require("@atlaskit/editor-common/monitoring");
13
+ var _errorHandling = require("../utils/errorHandling");
14
+ var _utils = require("../utils/utils");
15
+ /**
16
+ * Handles debounced batch-fetching of sync block data via `raf-schd`.
17
+ * Accumulates resource IDs and flushes them in a single fetch per
18
+ * animation frame.
19
+ */
20
+ var SyncBlockBatchFetcher = exports.SyncBlockBatchFetcher = /*#__PURE__*/function () {
21
+ function SyncBlockBatchFetcher(deps) {
22
+ var _this = this;
23
+ (0, _classCallCheck2.default)(this, SyncBlockBatchFetcher);
24
+ (0, _defineProperty2.default)(this, "pendingFetchRequests", new Set());
25
+ this.deps = deps;
26
+ this.scheduledBatchFetch = (0, _rafSchd.default)(function () {
27
+ if (_this.pendingFetchRequests.size === 0) {
28
+ return;
29
+ }
30
+ var resourceIds = Array.from(_this.pendingFetchRequests);
31
+ var syncBlockNodes = resourceIds.map(function (resId) {
32
+ var subscriptions = _this.deps.getSubscriptions().get(resId) || {};
33
+ var firstLocalId = Object.keys(subscriptions)[0] || '';
34
+ return (0, _utils.createSyncBlockNode)(firstLocalId, resId);
35
+ });
36
+ _this.pendingFetchRequests.clear();
37
+ _this.deps.fetchSyncBlocksData(syncBlockNodes).catch(function (error) {
38
+ (0, _monitoring.logException)(error, {
39
+ location: 'editor-synced-block-provider/syncBlockBatchFetcher/batchedFetchSyncBlocks'
40
+ });
41
+ resourceIds.forEach(function (resId) {
42
+ var _this$deps$getFireAna;
43
+ (_this$deps$getFireAna = _this.deps.getFireAnalyticsEvent()) === null || _this$deps$getFireAna === void 0 || _this$deps$getFireAna((0, _errorHandling.fetchErrorPayload)(error.message, resId));
44
+ });
45
+ });
46
+ });
47
+ }
48
+ return (0, _createClass2.default)(SyncBlockBatchFetcher, [{
49
+ key: "queueFetch",
50
+ value: function queueFetch(resourceId) {
51
+ var subscriptions = this.deps.getSubscriptions();
52
+ if (subscriptions.has(resourceId) && Object.keys(subscriptions.get(resourceId) || {}).length > 0) {
53
+ this.pendingFetchRequests.add(resourceId);
54
+ this.scheduledBatchFetch();
55
+ } else {
56
+ this.pendingFetchRequests.delete(resourceId);
57
+ }
58
+ }
59
+ }, {
60
+ key: "cancel",
61
+ value: function cancel() {
62
+ this.scheduledBatchFetch.cancel();
63
+ }
64
+ }, {
65
+ key: "clearPending",
66
+ value: function clearPending() {
67
+ this.pendingFetchRequests.clear();
68
+ }
69
+ }, {
70
+ key: "destroy",
71
+ value: function destroy() {
72
+ this.cancel();
73
+ this.clearPending();
74
+ }
75
+ }]);
76
+ }();
@@ -22,6 +22,13 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
22
22
  * (least-recently-used) entries are evicted first.
23
23
  */
24
24
  var SyncBlockInMemorySessionCache = exports.SyncBlockInMemorySessionCache = /*#__PURE__*/function () {
25
+ /**
26
+ * Maximum total size of all cached values, measured in **UTF-16 code
27
+ * units** (i.e. `String.prototype.length`), not bytes. For ASCII-only
28
+ * content the two are equivalent; for content with characters outside
29
+ * the BMP each surrogate pair counts as 2.
30
+ */
31
+
25
32
  function SyncBlockInMemorySessionCache() {
26
33
  var maxSize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 5 * 1024 * 1024;
27
34
  (0, _classCallCheck2.default)(this, SyncBlockInMemorySessionCache);
@@ -29,6 +36,14 @@ var SyncBlockInMemorySessionCache = exports.SyncBlockInMemorySessionCache = /*#_
29
36
  (0, _defineProperty2.default)(this, "currentSize", 0);
30
37
  this.maxSize = maxSize;
31
38
  }
39
+
40
+ /**
41
+ * Retrieves a cached value by key.
42
+ *
43
+ * **Side-effect:** promotes the entry to the most-recently-used
44
+ * position by re-inserting it at the end of the underlying Map's
45
+ * iteration order.
46
+ */
32
47
  return (0, _createClass2.default)(SyncBlockInMemorySessionCache, [{
33
48
  key: "getItem",
34
49
  value: function getItem(key) {
@@ -70,6 +85,17 @@ var SyncBlockInMemorySessionCache = exports.SyncBlockInMemorySessionCache = /*#_
70
85
  this.store.delete(key);
71
86
  }
72
87
  }
88
+
89
+ /**
90
+ * Removes all entries from the cache and resets the tracked size to zero.
91
+ * Useful for cleaning up the singleton on SPA navigation boundaries.
92
+ */
93
+ }, {
94
+ key: "clear",
95
+ value: function clear() {
96
+ this.store.clear();
97
+ this.currentSize = 0;
98
+ }
73
99
  }]);
74
100
  }();
75
101
  var syncBlockInMemorySessionCache = exports.syncBlockInMemorySessionCache = new SyncBlockInMemorySessionCache();
@@ -0,0 +1,175 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.SyncBlockProviderFactoryManager = void 0;
8
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+ var _monitoring = require("@atlaskit/editor-common/monitoring");
12
+ var _providerFactory = require("@atlaskit/editor-common/provider-factory");
13
+ var _errorHandling = require("../utils/errorHandling");
14
+ var _resourceId = require("../utils/resourceId");
15
+ /**
16
+ * Manages creation and caching of ProviderFactory instances used to
17
+ * render synced block content (media, emoji, smart links, etc.).
18
+ */
19
+ var SyncBlockProviderFactoryManager = exports.SyncBlockProviderFactoryManager = /*#__PURE__*/function () {
20
+ function SyncBlockProviderFactoryManager(deps) {
21
+ (0, _classCallCheck2.default)(this, SyncBlockProviderFactoryManager);
22
+ (0, _defineProperty2.default)(this, "providerFactories", new Map());
23
+ this.deps = deps;
24
+ }
25
+ return (0, _createClass2.default)(SyncBlockProviderFactoryManager, [{
26
+ key: "getProviderFactory",
27
+ value: function getProviderFactory(resourceId) {
28
+ var dataProvider = this.deps.getDataProvider();
29
+ if (!dataProvider) {
30
+ var _this$deps$getFireAna;
31
+ var error = new Error('Data provider not set');
32
+ (0, _monitoring.logException)(error, {
33
+ location: 'editor-synced-block-provider/syncBlockProviderFactoryManager'
34
+ });
35
+ (_this$deps$getFireAna = this.deps.getFireAnalyticsEvent()) === null || _this$deps$getFireAna === void 0 || _this$deps$getFireAna((0, _errorHandling.fetchErrorPayload)(error.message));
36
+ return undefined;
37
+ }
38
+ var _dataProvider$getSync = dataProvider.getSyncedBlockRendererProviderOptions(),
39
+ parentDataProviders = _dataProvider$getSync.parentDataProviders,
40
+ providerCreator = _dataProvider$getSync.providerCreator;
41
+ var providerFactory = this.providerFactories.get(resourceId);
42
+ if (!providerFactory) {
43
+ providerFactory = _providerFactory.ProviderFactory.create({
44
+ mentionProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.mentionProvider,
45
+ profilecardProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.profilecardProvider,
46
+ taskDecisionProvider: parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.taskDecisionProvider
47
+ });
48
+ this.providerFactories.set(resourceId, providerFactory);
49
+ } else {
50
+ if (parentDataProviders !== null && parentDataProviders !== void 0 && parentDataProviders.mentionProvider) {
51
+ providerFactory.setProvider('mentionProvider', parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.mentionProvider);
52
+ }
53
+ if (parentDataProviders !== null && parentDataProviders !== void 0 && parentDataProviders.profilecardProvider) {
54
+ providerFactory.setProvider('profilecardProvider', parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.profilecardProvider);
55
+ }
56
+ if (parentDataProviders !== null && parentDataProviders !== void 0 && parentDataProviders.taskDecisionProvider) {
57
+ providerFactory.setProvider('taskDecisionProvider', parentDataProviders === null || parentDataProviders === void 0 ? void 0 : parentDataProviders.taskDecisionProvider);
58
+ }
59
+ }
60
+ if (providerCreator) {
61
+ try {
62
+ this.retrieveDynamicProviders(resourceId, providerFactory, providerCreator);
63
+ } catch (error) {
64
+ var _this$deps$getFireAna2;
65
+ (0, _monitoring.logException)(error, {
66
+ location: 'editor-synced-block-provider/syncBlockProviderFactoryManager'
67
+ });
68
+ (_this$deps$getFireAna2 = this.deps.getFireAnalyticsEvent()) === null || _this$deps$getFireAna2 === void 0 || _this$deps$getFireAna2((0, _errorHandling.fetchErrorPayload)(error.message, resourceId));
69
+ }
70
+ }
71
+ return providerFactory;
72
+ }
73
+ }, {
74
+ key: "getSSRProviders",
75
+ value: function getSSRProviders(resourceId) {
76
+ var dataProvider = this.deps.getDataProvider();
77
+ if (!dataProvider) {
78
+ return null;
79
+ }
80
+ var _dataProvider$getSync2 = dataProvider.getSyncedBlockRendererProviderOptions(),
81
+ providerCreator = _dataProvider$getSync2.providerCreator;
82
+ if (!(providerCreator !== null && providerCreator !== void 0 && providerCreator.createSSRMediaProvider)) {
83
+ return null;
84
+ }
85
+ var parsedResourceId = (0, _resourceId.parseResourceId)(resourceId);
86
+ if (!parsedResourceId) {
87
+ return null;
88
+ }
89
+ var contentId = parsedResourceId.contentId,
90
+ contentProduct = parsedResourceId.product;
91
+ try {
92
+ var mediaProvider = providerCreator.createSSRMediaProvider({
93
+ contentId: contentId,
94
+ contentProduct: contentProduct
95
+ });
96
+ if (mediaProvider) {
97
+ return {
98
+ media: mediaProvider
99
+ };
100
+ }
101
+ } catch (error) {
102
+ (0, _monitoring.logException)(error, {
103
+ location: 'editor-synced-block-provider/syncBlockProviderFactoryManager'
104
+ });
105
+ }
106
+ return null;
107
+ }
108
+ }, {
109
+ key: "deleteFactory",
110
+ value: function deleteFactory(resourceId) {
111
+ this.providerFactories.delete(resourceId);
112
+ }
113
+ }, {
114
+ key: "destroy",
115
+ value: function destroy() {
116
+ this.providerFactories.forEach(function (pf) {
117
+ return pf.destroy();
118
+ });
119
+ this.providerFactories.clear();
120
+ }
121
+ }, {
122
+ key: "retrieveDynamicProviders",
123
+ value: function retrieveDynamicProviders(resourceId, providerFactory, providerCreator) {
124
+ var dataProvider = this.deps.getDataProvider();
125
+ if (!dataProvider) {
126
+ throw new Error('Data provider not set');
127
+ }
128
+ var hasMediaProvider = providerFactory.hasProvider('mediaProvider');
129
+ var hasEmojiProvider = providerFactory.hasProvider('emojiProvider');
130
+ var hasCardProvider = providerFactory.hasProvider('cardProvider');
131
+ if (hasMediaProvider && hasEmojiProvider && hasCardProvider) {
132
+ return;
133
+ }
134
+ var syncBlock = this.deps.getFromCache(resourceId);
135
+ if (!(syncBlock !== null && syncBlock !== void 0 && syncBlock.data)) {
136
+ return;
137
+ }
138
+ if (!syncBlock.data.sourceAri || !syncBlock.data.product) {
139
+ var _this$deps$getFireAna3;
140
+ (_this$deps$getFireAna3 = this.deps.getFireAnalyticsEvent()) === null || _this$deps$getFireAna3 === void 0 || _this$deps$getFireAna3((0, _errorHandling.fetchErrorPayload)('Sync block source ari or product not found'));
141
+ return;
142
+ }
143
+ var parentInfo = dataProvider.retrieveSyncBlockParentInfo(syncBlock.data.sourceAri, syncBlock.data.product);
144
+ if (!parentInfo) {
145
+ throw new Error('Unable to retrieve sync block parent info');
146
+ }
147
+ var contentId = parentInfo.contentId,
148
+ contentProduct = parentInfo.contentProduct;
149
+ if (!hasMediaProvider && providerCreator.createMediaProvider && contentId && contentProduct) {
150
+ var mediaProvider = providerCreator.createMediaProvider({
151
+ contentProduct: contentProduct,
152
+ contentId: contentId
153
+ });
154
+ if (mediaProvider) {
155
+ providerFactory.setProvider('mediaProvider', mediaProvider);
156
+ }
157
+ }
158
+ if (!hasEmojiProvider && providerCreator.createEmojiProvider && contentId && contentProduct) {
159
+ var emojiProvider = providerCreator.createEmojiProvider({
160
+ contentProduct: contentProduct,
161
+ contentId: contentId
162
+ });
163
+ if (emojiProvider) {
164
+ providerFactory.setProvider('emojiProvider', emojiProvider);
165
+ }
166
+ }
167
+ if (!hasCardProvider && providerCreator.createSmartLinkProvider) {
168
+ var smartLinkProvider = providerCreator.createSmartLinkProvider();
169
+ if (smartLinkProvider) {
170
+ providerFactory.setProvider('cardProvider', smartLinkProvider);
171
+ }
172
+ }
173
+ }
174
+ }]);
175
+ }();