@atlaskit/editor-synced-block-provider 3.29.0 → 3.29.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.
- package/CHANGELOG.md +8 -0
- package/dist/cjs/index.js +7 -0
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +101 -33
- package/dist/es2019/index.js +1 -2
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +74 -14
- package/dist/esm/index.js +1 -2
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +100 -33
- package/dist/types/index.d.ts +1 -1
- package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +3 -0
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +3 -0
- package/package.json +5 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @atlaskit/editor-synced-block-provider
|
|
2
2
|
|
|
3
|
+
## 3.29.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`53c9f85806f98`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/53c9f85806f98) -
|
|
8
|
+
EDITOR-5275 Store synced blocks data in session storage for look up during page transitions
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
3
11
|
## 3.29.0
|
|
4
12
|
|
|
5
13
|
### Minor Changes
|
package/dist/cjs/index.js
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
Object.defineProperty(exports, "ReferenceSyncBlockStoreManager", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _referenceSyncBlockStoreManager.ReferenceSyncBlockStoreManager;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
6
12
|
Object.defineProperty(exports, "SyncBlockError", {
|
|
7
13
|
enumerable: true,
|
|
8
14
|
get: function get() {
|
|
@@ -213,6 +219,7 @@ var _ari3 = require("./clients/jira/ari");
|
|
|
213
219
|
var _blockServiceAPI = require("./providers/block-service/blockServiceAPI");
|
|
214
220
|
var _sourceInfo = require("./clients/confluence/sourceInfo");
|
|
215
221
|
var _syncBlockProvider = require("./providers/syncBlockProvider");
|
|
222
|
+
var _referenceSyncBlockStoreManager = require("./store-manager/referenceSyncBlockStoreManager");
|
|
216
223
|
var _syncBlockStoreManager = require("./store-manager/syncBlockStoreManager");
|
|
217
224
|
var _resolveSyncBlockInstance = require("./utils/resolveSyncBlockInstance");
|
|
218
225
|
var _resourceId = require("./utils/resourceId");
|
|
@@ -27,6 +27,8 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
27
27
|
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; } } }; }
|
|
28
28
|
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; } }
|
|
29
29
|
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; }
|
|
30
|
+
var SESSION_STORAGE_KEY_PREFIX = 'sync-block-data-';
|
|
31
|
+
|
|
30
32
|
// A store manager responsible for the lifecycle and state management of reference sync blocks in an editor instance.
|
|
31
33
|
// Designed to manage local in-memory state and synchronize with an external data provider.
|
|
32
34
|
// Supports fetch, cache, and subscription for sync block data.
|
|
@@ -34,7 +36,8 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
|
|
|
34
36
|
// Can be used in both editor and renderer contexts.
|
|
35
37
|
var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
36
38
|
function ReferenceSyncBlockStoreManager(dataProvider) {
|
|
37
|
-
var _this = this
|
|
39
|
+
var _this = this,
|
|
40
|
+
_this$dataProvider;
|
|
38
41
|
(0, _classCallCheck2.default)(this, ReferenceSyncBlockStoreManager);
|
|
39
42
|
// Keeps track of addition and deletion of reference synced blocks on the document
|
|
40
43
|
// This starts as true to always flush the cache when document is saved for the first time
|
|
@@ -81,6 +84,9 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
81
84
|
this.graphqlSubscriptions = new Map();
|
|
82
85
|
this.subscriptionChangeListeners = new Set();
|
|
83
86
|
this.newlyAddedSyncBlocks = new Set();
|
|
87
|
+
|
|
88
|
+
// The provider might have SSR data cache already set, so we need to update the cache in session storage
|
|
89
|
+
this.setSSRDataInSessionStorage((_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.getNodeDataCacheKeys());
|
|
84
90
|
}
|
|
85
91
|
|
|
86
92
|
/**
|
|
@@ -217,9 +223,57 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
217
223
|
}, {
|
|
218
224
|
key: "getInitialSyncBlockData",
|
|
219
225
|
value: function getInitialSyncBlockData(resourceId) {
|
|
220
|
-
var _this$
|
|
226
|
+
var _this$dataProvider2;
|
|
221
227
|
var syncBlockNode = (0, _utils.createSyncBlockNode)('', resourceId);
|
|
222
|
-
|
|
228
|
+
var data = (_this$dataProvider2 = this.dataProvider) === null || _this$dataProvider2 === void 0 || (_this$dataProvider2 = _this$dataProvider2.getNodeDataFromCache(syncBlockNode)) === null || _this$dataProvider2 === void 0 ? void 0 : _this$dataProvider2.data;
|
|
229
|
+
if (data) {
|
|
230
|
+
return data;
|
|
231
|
+
}
|
|
232
|
+
if ((0, _platformFeatureFlags.fg)('platform_synced_block_patch_3')) {
|
|
233
|
+
var sessionData = this.getSyncBlockDataFromSessionStorage(resourceId);
|
|
234
|
+
if (sessionData) {
|
|
235
|
+
return sessionData;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return undefined;
|
|
239
|
+
}
|
|
240
|
+
}, {
|
|
241
|
+
key: "updateCacheInSessionStorage",
|
|
242
|
+
value: function updateCacheInSessionStorage(resourceId) {
|
|
243
|
+
try {
|
|
244
|
+
var latestData = this.getFromCache(resourceId);
|
|
245
|
+
if (latestData) {
|
|
246
|
+
sessionStorage.setItem("".concat(SESSION_STORAGE_KEY_PREFIX).concat(resourceId), JSON.stringify(latestData));
|
|
247
|
+
}
|
|
248
|
+
} catch (error) {
|
|
249
|
+
(0, _monitoring.logException)(error, {
|
|
250
|
+
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager/updateCacheInSessionStorage'
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}, {
|
|
255
|
+
key: "getSyncBlockDataFromSessionStorage",
|
|
256
|
+
value: function getSyncBlockDataFromSessionStorage(resourceId) {
|
|
257
|
+
var sessionData = null;
|
|
258
|
+
try {
|
|
259
|
+
sessionData = sessionStorage.getItem("".concat(SESSION_STORAGE_KEY_PREFIX).concat(resourceId));
|
|
260
|
+
} catch (error) {
|
|
261
|
+
(0, _monitoring.logException)(error, {
|
|
262
|
+
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager/getSyncBlockDataFromSessionStorage'
|
|
263
|
+
});
|
|
264
|
+
return undefined;
|
|
265
|
+
}
|
|
266
|
+
if (!sessionData) {
|
|
267
|
+
return undefined;
|
|
268
|
+
}
|
|
269
|
+
try {
|
|
270
|
+
return JSON.parse(sessionData);
|
|
271
|
+
} catch (error) {
|
|
272
|
+
(0, _monitoring.logException)(error, {
|
|
273
|
+
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager/getSyncBlockDataFromSessionStorage'
|
|
274
|
+
});
|
|
275
|
+
return undefined;
|
|
276
|
+
}
|
|
223
277
|
}
|
|
224
278
|
|
|
225
279
|
/**
|
|
@@ -324,13 +378,13 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
324
378
|
}, {
|
|
325
379
|
key: "setupGraphQLSubscription",
|
|
326
380
|
value: function setupGraphQLSubscription(resourceId) {
|
|
327
|
-
var _this$
|
|
381
|
+
var _this$dataProvider3,
|
|
328
382
|
_this4 = this;
|
|
329
383
|
// Don't set up duplicate subscriptions
|
|
330
384
|
if (this.graphqlSubscriptions.has(resourceId)) {
|
|
331
385
|
return;
|
|
332
386
|
}
|
|
333
|
-
if (!((_this$
|
|
387
|
+
if (!((_this$dataProvider3 = this.dataProvider) !== null && _this$dataProvider3 !== void 0 && _this$dataProvider3.subscribeToBlockUpdates)) {
|
|
334
388
|
return;
|
|
335
389
|
}
|
|
336
390
|
var unsubscribe = this.dataProvider.subscribeToBlockUpdates(resourceId, function (syncBlockInstance) {
|
|
@@ -773,8 +827,8 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
773
827
|
value: function updateCache(syncBlock) {
|
|
774
828
|
var resourceId = syncBlock.resourceId;
|
|
775
829
|
if (resourceId) {
|
|
776
|
-
var _this$
|
|
777
|
-
(_this$
|
|
830
|
+
var _this$dataProvider4;
|
|
831
|
+
(_this$dataProvider4 = this.dataProvider) === null || _this$dataProvider4 === void 0 || _this$dataProvider4.updateCache((0, _defineProperty2.default)({}, resourceId, syncBlock), {
|
|
778
832
|
strategy: 'merge',
|
|
779
833
|
source: 'network'
|
|
780
834
|
});
|
|
@@ -784,6 +838,9 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
784
838
|
callback(syncBlock);
|
|
785
839
|
});
|
|
786
840
|
}
|
|
841
|
+
if ((0, _platformFeatureFlags.fg)('platform_synced_block_patch_3')) {
|
|
842
|
+
this.updateCacheInSessionStorage(resourceId);
|
|
843
|
+
}
|
|
787
844
|
}
|
|
788
845
|
}
|
|
789
846
|
}, {
|
|
@@ -799,15 +856,15 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
799
856
|
}, {
|
|
800
857
|
key: "getFromCache",
|
|
801
858
|
value: function getFromCache(resourceId) {
|
|
802
|
-
var _this$
|
|
859
|
+
var _this$dataProvider5;
|
|
803
860
|
var syncBlockNode = (0, _utils.createSyncBlockNode)('', resourceId);
|
|
804
|
-
return (_this$
|
|
861
|
+
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;
|
|
805
862
|
}
|
|
806
863
|
}, {
|
|
807
864
|
key: "deleteFromCache",
|
|
808
865
|
value: function deleteFromCache(resourceId) {
|
|
809
|
-
var _this$
|
|
810
|
-
(_this$
|
|
866
|
+
var _this$dataProvider6;
|
|
867
|
+
(_this$dataProvider6 = this.dataProvider) === null || _this$dataProvider6 === void 0 || _this$dataProvider6.removeFromCache([resourceId]);
|
|
811
868
|
this.providerFactories.delete(resourceId);
|
|
812
869
|
}
|
|
813
870
|
}, {
|
|
@@ -826,11 +883,22 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
826
883
|
this.scheduledBatchFetch();
|
|
827
884
|
}
|
|
828
885
|
}
|
|
886
|
+
}, {
|
|
887
|
+
key: "setSSRDataInSessionStorage",
|
|
888
|
+
value: function setSSRDataInSessionStorage(resourceIds) {
|
|
889
|
+
var _this0 = this;
|
|
890
|
+
if (!resourceIds || resourceIds.length === 0) {
|
|
891
|
+
return;
|
|
892
|
+
}
|
|
893
|
+
resourceIds.forEach(function (resourceId) {
|
|
894
|
+
_this0.updateCacheInSessionStorage(resourceId);
|
|
895
|
+
});
|
|
896
|
+
}
|
|
829
897
|
}, {
|
|
830
898
|
key: "subscribeToSyncBlock",
|
|
831
899
|
value: function subscribeToSyncBlock(resourceId, localId, callback) {
|
|
832
|
-
var _this$
|
|
833
|
-
|
|
900
|
+
var _this$dataProvider7,
|
|
901
|
+
_this1 = this;
|
|
834
902
|
// Cancel any pending cache deletion for this resourceId.
|
|
835
903
|
// This handles the case where a block is moved - the old component unmounts
|
|
836
904
|
// (scheduling deletion) but the new component mounts and subscribes before
|
|
@@ -856,7 +924,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
856
924
|
var syncBlockNode = (0, _utils.createSyncBlockNode)(localId, resourceId);
|
|
857
925
|
|
|
858
926
|
// call the callback immediately if we have cached data
|
|
859
|
-
var cachedData = (_this$
|
|
927
|
+
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;
|
|
860
928
|
if (cachedData) {
|
|
861
929
|
callback(cachedData);
|
|
862
930
|
} else {
|
|
@@ -868,19 +936,19 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
868
936
|
this.setupGraphQLSubscription(resourceId);
|
|
869
937
|
}
|
|
870
938
|
return function () {
|
|
871
|
-
var resourceSubscriptions =
|
|
939
|
+
var resourceSubscriptions = _this1.subscriptions.get(resourceId);
|
|
872
940
|
if (resourceSubscriptions) {
|
|
873
941
|
// Unsubscription means a reference synced block is removed from the document
|
|
874
|
-
|
|
942
|
+
_this1.isCacheDirty = true;
|
|
875
943
|
delete resourceSubscriptions[localId];
|
|
876
944
|
if (Object.keys(resourceSubscriptions).length === 0) {
|
|
877
|
-
|
|
945
|
+
_this1.subscriptions.delete(resourceId);
|
|
878
946
|
|
|
879
947
|
// Clean up GraphQL subscription when no more local subscribers
|
|
880
|
-
|
|
948
|
+
_this1.cleanupGraphQLSubscription(resourceId);
|
|
881
949
|
|
|
882
950
|
// Notify listeners that subscription was removed
|
|
883
|
-
|
|
951
|
+
_this1.notifySubscriptionChangeListeners();
|
|
884
952
|
|
|
885
953
|
// Delay cache deletion to handle block moves (unmount/remount).
|
|
886
954
|
// When a block is moved, the old component unmounts before the new one mounts.
|
|
@@ -889,14 +957,14 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
889
957
|
// TODO: EDITOR-4152 - Rework this logic
|
|
890
958
|
var deletionTimeout = setTimeout(function () {
|
|
891
959
|
// Only delete if still no subscribers (wasn't re-subscribed)
|
|
892
|
-
if (!
|
|
893
|
-
|
|
960
|
+
if (!_this1.subscriptions.has(resourceId)) {
|
|
961
|
+
_this1.deleteFromCache(resourceId);
|
|
894
962
|
}
|
|
895
|
-
|
|
963
|
+
_this1.pendingCacheDeletions.delete(resourceId);
|
|
896
964
|
}, 1000);
|
|
897
|
-
|
|
965
|
+
_this1.pendingCacheDeletions.set(resourceId, deletionTimeout);
|
|
898
966
|
} else {
|
|
899
|
-
|
|
967
|
+
_this1.subscriptions.set(resourceId, resourceSubscriptions);
|
|
900
968
|
}
|
|
901
969
|
}
|
|
902
970
|
};
|
|
@@ -905,7 +973,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
905
973
|
key: "subscribeToSourceTitle",
|
|
906
974
|
value: function subscribeToSourceTitle(node, callback) {
|
|
907
975
|
var _cachedData$data,
|
|
908
|
-
|
|
976
|
+
_this10 = this;
|
|
909
977
|
// check node is a sync block, as we only support sync block subscriptions
|
|
910
978
|
if (node.type.name !== 'syncBlock') {
|
|
911
979
|
return function () {};
|
|
@@ -925,13 +993,13 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
925
993
|
var resourceSubscriptions = this.titleSubscriptions.get(resourceId) || {};
|
|
926
994
|
this.titleSubscriptions.set(resourceId, _objectSpread(_objectSpread({}, resourceSubscriptions), {}, (0, _defineProperty2.default)({}, localId, callback)));
|
|
927
995
|
return function () {
|
|
928
|
-
var resourceSubscriptions =
|
|
996
|
+
var resourceSubscriptions = _this10.titleSubscriptions.get(resourceId);
|
|
929
997
|
if (resourceSubscriptions) {
|
|
930
998
|
delete resourceSubscriptions[localId];
|
|
931
999
|
if (Object.keys(resourceSubscriptions).length === 0) {
|
|
932
|
-
|
|
1000
|
+
_this10.titleSubscriptions.delete(resourceId);
|
|
933
1001
|
} else {
|
|
934
|
-
|
|
1002
|
+
_this10.titleSubscriptions.set(resourceId, resourceSubscriptions);
|
|
935
1003
|
}
|
|
936
1004
|
}
|
|
937
1005
|
};
|
|
@@ -1126,7 +1194,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
1126
1194
|
key: "flush",
|
|
1127
1195
|
value: (function () {
|
|
1128
1196
|
var _flush = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4() {
|
|
1129
|
-
var
|
|
1197
|
+
var _this11 = this;
|
|
1130
1198
|
var success, syncedBlocksToFlush, _this$saveExperience, blocks, _iterator4, _step4, _loop2, updateResult, _this$saveExperience2, _this$fireAnalyticsEv1, _this$saveExperience3, _this$fireAnalyticsEv10, _this$saveExperience4;
|
|
1131
1199
|
return _regenerator.default.wrap(function _callee4$(_context6) {
|
|
1132
1200
|
while (1) switch (_context6.prev = _context6.next) {
|
|
@@ -1288,8 +1356,8 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
1288
1356
|
// Use setTimeout to avoid deep recursion and run queued flush asynchronously
|
|
1289
1357
|
// Note: flush() handles all exceptions internally and never rejects
|
|
1290
1358
|
this.queuedFlushTimeout = setTimeout(function () {
|
|
1291
|
-
|
|
1292
|
-
void
|
|
1359
|
+
_this11.queuedFlushTimeout = undefined;
|
|
1360
|
+
void _this11.flush();
|
|
1293
1361
|
}, 0);
|
|
1294
1362
|
}
|
|
1295
1363
|
}
|
|
@@ -1310,7 +1378,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
1310
1378
|
}, {
|
|
1311
1379
|
key: "destroy",
|
|
1312
1380
|
value: function destroy() {
|
|
1313
|
-
var _this$
|
|
1381
|
+
var _this$dataProvider8, _this$saveExperience5, _this$fetchExperience0, _this$fetchSourceInfo2;
|
|
1314
1382
|
// Cancel any queued flush to prevent it from running after destroy
|
|
1315
1383
|
if (this.queuedFlushTimeout) {
|
|
1316
1384
|
clearTimeout(this.queuedFlushTimeout);
|
|
@@ -1319,7 +1387,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
1319
1387
|
|
|
1320
1388
|
// Clean up all GraphQL subscriptions first
|
|
1321
1389
|
this.cleanupAllGraphQLSubscriptions();
|
|
1322
|
-
(_this$
|
|
1390
|
+
(_this$dataProvider8 = this.dataProvider) === null || _this$dataProvider8 === void 0 || _this$dataProvider8.resetCache();
|
|
1323
1391
|
this.scheduledBatchFetch.cancel();
|
|
1324
1392
|
this.pendingFetchRequests.clear();
|
|
1325
1393
|
this.dataProvider = undefined;
|
package/dist/es2019/index.js
CHANGED
|
@@ -18,9 +18,8 @@ export { getJiraWorkItemAri, getJiraWorkItemIdFromAri } from './clients/jira/ari
|
|
|
18
18
|
export { useMemoizedBlockServiceAPIProviders, useMemoizedBlockServiceFetchOnlyAPIProvider, fetchReferences, batchFetchData } from './providers/block-service/blockServiceAPI';
|
|
19
19
|
export { fetchConfluencePageInfo } from './clients/confluence/sourceInfo';
|
|
20
20
|
export { SyncBlockProvider as SyncedBlockProvider, useMemoizedSyncedBlockProvider } from './providers/syncBlockProvider';
|
|
21
|
-
|
|
22
21
|
// store managers
|
|
23
|
-
|
|
22
|
+
export { ReferenceSyncBlockStoreManager } from './store-manager/referenceSyncBlockStoreManager';
|
|
24
23
|
export { SyncBlockStoreManager, useMemoizedSyncBlockStoreManager } from './store-manager/syncBlockStoreManager';
|
|
25
24
|
|
|
26
25
|
// utils
|
|
@@ -10,6 +10,7 @@ import { getFetchExperience, getFetchSourceInfoExperience, getSaveReferenceExper
|
|
|
10
10
|
import { resolveSyncBlockInstance } from '../utils/resolveSyncBlockInstance';
|
|
11
11
|
import { parseResourceId } from '../utils/resourceId';
|
|
12
12
|
import { createSyncBlockNode } from '../utils/utils';
|
|
13
|
+
const SESSION_STORAGE_KEY_PREFIX = 'sync-block-data-';
|
|
13
14
|
|
|
14
15
|
// A store manager responsible for the lifecycle and state management of reference sync blocks in an editor instance.
|
|
15
16
|
// Designed to manage local in-memory state and synchronize with an external data provider.
|
|
@@ -18,6 +19,7 @@ import { createSyncBlockNode } from '../utils/utils';
|
|
|
18
19
|
// Can be used in both editor and renderer contexts.
|
|
19
20
|
export class ReferenceSyncBlockStoreManager {
|
|
20
21
|
constructor(dataProvider) {
|
|
22
|
+
var _this$dataProvider;
|
|
21
23
|
// Keeps track of addition and deletion of reference synced blocks on the document
|
|
22
24
|
// This starts as true to always flush the cache when document is saved for the first time
|
|
23
25
|
// to cater the case when a editor session is closed without document being updated right after reference block is deleted
|
|
@@ -63,6 +65,9 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
63
65
|
this.graphqlSubscriptions = new Map();
|
|
64
66
|
this.subscriptionChangeListeners = new Set();
|
|
65
67
|
this.newlyAddedSyncBlocks = new Set();
|
|
68
|
+
|
|
69
|
+
// The provider might have SSR data cache already set, so we need to update the cache in session storage
|
|
70
|
+
this.setSSRDataInSessionStorage((_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.getNodeDataCacheKeys());
|
|
66
71
|
}
|
|
67
72
|
|
|
68
73
|
/**
|
|
@@ -173,9 +178,53 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
173
178
|
this.fireAnalyticsEvent = fireAnalyticsEvent;
|
|
174
179
|
}
|
|
175
180
|
getInitialSyncBlockData(resourceId) {
|
|
176
|
-
var _this$
|
|
181
|
+
var _this$dataProvider2, _this$dataProvider2$g;
|
|
177
182
|
const syncBlockNode = createSyncBlockNode('', resourceId);
|
|
178
|
-
|
|
183
|
+
const data = (_this$dataProvider2 = this.dataProvider) === null || _this$dataProvider2 === void 0 ? void 0 : (_this$dataProvider2$g = _this$dataProvider2.getNodeDataFromCache(syncBlockNode)) === null || _this$dataProvider2$g === void 0 ? void 0 : _this$dataProvider2$g.data;
|
|
184
|
+
if (data) {
|
|
185
|
+
return data;
|
|
186
|
+
}
|
|
187
|
+
if (fg('platform_synced_block_patch_3')) {
|
|
188
|
+
const sessionData = this.getSyncBlockDataFromSessionStorage(resourceId);
|
|
189
|
+
if (sessionData) {
|
|
190
|
+
return sessionData;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return undefined;
|
|
194
|
+
}
|
|
195
|
+
updateCacheInSessionStorage(resourceId) {
|
|
196
|
+
try {
|
|
197
|
+
const latestData = this.getFromCache(resourceId);
|
|
198
|
+
if (latestData) {
|
|
199
|
+
sessionStorage.setItem(`${SESSION_STORAGE_KEY_PREFIX}${resourceId}`, JSON.stringify(latestData));
|
|
200
|
+
}
|
|
201
|
+
} catch (error) {
|
|
202
|
+
logException(error, {
|
|
203
|
+
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager/updateCacheInSessionStorage'
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
getSyncBlockDataFromSessionStorage(resourceId) {
|
|
208
|
+
let sessionData = null;
|
|
209
|
+
try {
|
|
210
|
+
sessionData = sessionStorage.getItem(`${SESSION_STORAGE_KEY_PREFIX}${resourceId}`);
|
|
211
|
+
} catch (error) {
|
|
212
|
+
logException(error, {
|
|
213
|
+
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager/getSyncBlockDataFromSessionStorage'
|
|
214
|
+
});
|
|
215
|
+
return undefined;
|
|
216
|
+
}
|
|
217
|
+
if (!sessionData) {
|
|
218
|
+
return undefined;
|
|
219
|
+
}
|
|
220
|
+
try {
|
|
221
|
+
return JSON.parse(sessionData);
|
|
222
|
+
} catch (error) {
|
|
223
|
+
logException(error, {
|
|
224
|
+
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager/getSyncBlockDataFromSessionStorage'
|
|
225
|
+
});
|
|
226
|
+
return undefined;
|
|
227
|
+
}
|
|
179
228
|
}
|
|
180
229
|
|
|
181
230
|
/**
|
|
@@ -218,12 +267,12 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
218
267
|
* @param resourceId - The resource ID of the block to subscribe to
|
|
219
268
|
*/
|
|
220
269
|
setupGraphQLSubscription(resourceId) {
|
|
221
|
-
var _this$
|
|
270
|
+
var _this$dataProvider3;
|
|
222
271
|
// Don't set up duplicate subscriptions
|
|
223
272
|
if (this.graphqlSubscriptions.has(resourceId)) {
|
|
224
273
|
return;
|
|
225
274
|
}
|
|
226
|
-
if (!((_this$
|
|
275
|
+
if (!((_this$dataProvider3 = this.dataProvider) !== null && _this$dataProvider3 !== void 0 && _this$dataProvider3.subscribeToBlockUpdates)) {
|
|
227
276
|
return;
|
|
228
277
|
}
|
|
229
278
|
const unsubscribe = this.dataProvider.subscribeToBlockUpdates(resourceId, syncBlockInstance => {
|
|
@@ -585,8 +634,8 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
585
634
|
resourceId
|
|
586
635
|
} = syncBlock;
|
|
587
636
|
if (resourceId) {
|
|
588
|
-
var _this$
|
|
589
|
-
(_this$
|
|
637
|
+
var _this$dataProvider4;
|
|
638
|
+
(_this$dataProvider4 = this.dataProvider) === null || _this$dataProvider4 === void 0 ? void 0 : _this$dataProvider4.updateCache({
|
|
590
639
|
[resourceId]: syncBlock
|
|
591
640
|
}, {
|
|
592
641
|
strategy: 'merge',
|
|
@@ -598,6 +647,9 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
598
647
|
callback(syncBlock);
|
|
599
648
|
});
|
|
600
649
|
}
|
|
650
|
+
if (fg('platform_synced_block_patch_3')) {
|
|
651
|
+
this.updateCacheInSessionStorage(resourceId);
|
|
652
|
+
}
|
|
601
653
|
}
|
|
602
654
|
}
|
|
603
655
|
updateSourceTitleSubscriptions(resourceId, title) {
|
|
@@ -609,13 +661,13 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
609
661
|
}
|
|
610
662
|
}
|
|
611
663
|
getFromCache(resourceId) {
|
|
612
|
-
var _this$
|
|
664
|
+
var _this$dataProvider5, _this$dataProvider5$g;
|
|
613
665
|
const syncBlockNode = createSyncBlockNode('', resourceId);
|
|
614
|
-
return (_this$
|
|
666
|
+
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;
|
|
615
667
|
}
|
|
616
668
|
deleteFromCache(resourceId) {
|
|
617
|
-
var _this$
|
|
618
|
-
(_this$
|
|
669
|
+
var _this$dataProvider6;
|
|
670
|
+
(_this$dataProvider6 = this.dataProvider) === null || _this$dataProvider6 === void 0 ? void 0 : _this$dataProvider6.removeFromCache([resourceId]);
|
|
619
671
|
this.providerFactories.delete(resourceId);
|
|
620
672
|
}
|
|
621
673
|
debouncedBatchedFetchSyncBlocks(resourceId) {
|
|
@@ -632,8 +684,16 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
632
684
|
this.scheduledBatchFetch();
|
|
633
685
|
}
|
|
634
686
|
}
|
|
687
|
+
setSSRDataInSessionStorage(resourceIds) {
|
|
688
|
+
if (!resourceIds || resourceIds.length === 0) {
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
resourceIds.forEach(resourceId => {
|
|
692
|
+
this.updateCacheInSessionStorage(resourceId);
|
|
693
|
+
});
|
|
694
|
+
}
|
|
635
695
|
subscribeToSyncBlock(resourceId, localId, callback) {
|
|
636
|
-
var _this$
|
|
696
|
+
var _this$dataProvider7, _this$dataProvider7$g;
|
|
637
697
|
// Cancel any pending cache deletion for this resourceId.
|
|
638
698
|
// This handles the case where a block is moved - the old component unmounts
|
|
639
699
|
// (scheduling deletion) but the new component mounts and subscribes before
|
|
@@ -662,7 +722,7 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
662
722
|
const syncBlockNode = createSyncBlockNode(localId, resourceId);
|
|
663
723
|
|
|
664
724
|
// call the callback immediately if we have cached data
|
|
665
|
-
const cachedData = (_this$
|
|
725
|
+
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;
|
|
666
726
|
if (cachedData) {
|
|
667
727
|
callback(cachedData);
|
|
668
728
|
} else {
|
|
@@ -1043,7 +1103,7 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
1043
1103
|
return success;
|
|
1044
1104
|
}
|
|
1045
1105
|
destroy() {
|
|
1046
|
-
var _this$
|
|
1106
|
+
var _this$dataProvider8, _this$saveExperience5, _this$fetchExperience0, _this$fetchSourceInfo6;
|
|
1047
1107
|
// Cancel any queued flush to prevent it from running after destroy
|
|
1048
1108
|
if (this.queuedFlushTimeout) {
|
|
1049
1109
|
clearTimeout(this.queuedFlushTimeout);
|
|
@@ -1052,7 +1112,7 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
1052
1112
|
|
|
1053
1113
|
// Clean up all GraphQL subscriptions first
|
|
1054
1114
|
this.cleanupAllGraphQLSubscriptions();
|
|
1055
|
-
(_this$
|
|
1115
|
+
(_this$dataProvider8 = this.dataProvider) === null || _this$dataProvider8 === void 0 ? void 0 : _this$dataProvider8.resetCache();
|
|
1056
1116
|
this.scheduledBatchFetch.cancel();
|
|
1057
1117
|
this.pendingFetchRequests.clear();
|
|
1058
1118
|
this.dataProvider = undefined;
|
package/dist/esm/index.js
CHANGED
|
@@ -18,9 +18,8 @@ export { getJiraWorkItemAri, getJiraWorkItemIdFromAri } from './clients/jira/ari
|
|
|
18
18
|
export { useMemoizedBlockServiceAPIProviders, useMemoizedBlockServiceFetchOnlyAPIProvider, fetchReferences, batchFetchData } from './providers/block-service/blockServiceAPI';
|
|
19
19
|
export { fetchConfluencePageInfo } from './clients/confluence/sourceInfo';
|
|
20
20
|
export { SyncBlockProvider as SyncedBlockProvider, useMemoizedSyncedBlockProvider } from './providers/syncBlockProvider';
|
|
21
|
-
|
|
22
21
|
// store managers
|
|
23
|
-
|
|
22
|
+
export { ReferenceSyncBlockStoreManager } from './store-manager/referenceSyncBlockStoreManager';
|
|
24
23
|
export { SyncBlockStoreManager, useMemoizedSyncBlockStoreManager } from './store-manager/syncBlockStoreManager';
|
|
25
24
|
|
|
26
25
|
// utils
|
|
@@ -20,6 +20,7 @@ import { getFetchExperience, getFetchSourceInfoExperience, getSaveReferenceExper
|
|
|
20
20
|
import { resolveSyncBlockInstance } from '../utils/resolveSyncBlockInstance';
|
|
21
21
|
import { parseResourceId } from '../utils/resourceId';
|
|
22
22
|
import { createSyncBlockNode } from '../utils/utils';
|
|
23
|
+
var SESSION_STORAGE_KEY_PREFIX = 'sync-block-data-';
|
|
23
24
|
|
|
24
25
|
// A store manager responsible for the lifecycle and state management of reference sync blocks in an editor instance.
|
|
25
26
|
// Designed to manage local in-memory state and synchronize with an external data provider.
|
|
@@ -28,7 +29,8 @@ import { createSyncBlockNode } from '../utils/utils';
|
|
|
28
29
|
// Can be used in both editor and renderer contexts.
|
|
29
30
|
export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
30
31
|
function ReferenceSyncBlockStoreManager(dataProvider) {
|
|
31
|
-
var _this = this
|
|
32
|
+
var _this = this,
|
|
33
|
+
_this$dataProvider;
|
|
32
34
|
_classCallCheck(this, ReferenceSyncBlockStoreManager);
|
|
33
35
|
// Keeps track of addition and deletion of reference synced blocks on the document
|
|
34
36
|
// This starts as true to always flush the cache when document is saved for the first time
|
|
@@ -75,6 +77,9 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
75
77
|
this.graphqlSubscriptions = new Map();
|
|
76
78
|
this.subscriptionChangeListeners = new Set();
|
|
77
79
|
this.newlyAddedSyncBlocks = new Set();
|
|
80
|
+
|
|
81
|
+
// The provider might have SSR data cache already set, so we need to update the cache in session storage
|
|
82
|
+
this.setSSRDataInSessionStorage((_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.getNodeDataCacheKeys());
|
|
78
83
|
}
|
|
79
84
|
|
|
80
85
|
/**
|
|
@@ -211,9 +216,57 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
211
216
|
}, {
|
|
212
217
|
key: "getInitialSyncBlockData",
|
|
213
218
|
value: function getInitialSyncBlockData(resourceId) {
|
|
214
|
-
var _this$
|
|
219
|
+
var _this$dataProvider2;
|
|
215
220
|
var syncBlockNode = createSyncBlockNode('', resourceId);
|
|
216
|
-
|
|
221
|
+
var data = (_this$dataProvider2 = this.dataProvider) === null || _this$dataProvider2 === void 0 || (_this$dataProvider2 = _this$dataProvider2.getNodeDataFromCache(syncBlockNode)) === null || _this$dataProvider2 === void 0 ? void 0 : _this$dataProvider2.data;
|
|
222
|
+
if (data) {
|
|
223
|
+
return data;
|
|
224
|
+
}
|
|
225
|
+
if (fg('platform_synced_block_patch_3')) {
|
|
226
|
+
var sessionData = this.getSyncBlockDataFromSessionStorage(resourceId);
|
|
227
|
+
if (sessionData) {
|
|
228
|
+
return sessionData;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return undefined;
|
|
232
|
+
}
|
|
233
|
+
}, {
|
|
234
|
+
key: "updateCacheInSessionStorage",
|
|
235
|
+
value: function updateCacheInSessionStorage(resourceId) {
|
|
236
|
+
try {
|
|
237
|
+
var latestData = this.getFromCache(resourceId);
|
|
238
|
+
if (latestData) {
|
|
239
|
+
sessionStorage.setItem("".concat(SESSION_STORAGE_KEY_PREFIX).concat(resourceId), JSON.stringify(latestData));
|
|
240
|
+
}
|
|
241
|
+
} catch (error) {
|
|
242
|
+
logException(error, {
|
|
243
|
+
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager/updateCacheInSessionStorage'
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}, {
|
|
248
|
+
key: "getSyncBlockDataFromSessionStorage",
|
|
249
|
+
value: function getSyncBlockDataFromSessionStorage(resourceId) {
|
|
250
|
+
var sessionData = null;
|
|
251
|
+
try {
|
|
252
|
+
sessionData = sessionStorage.getItem("".concat(SESSION_STORAGE_KEY_PREFIX).concat(resourceId));
|
|
253
|
+
} catch (error) {
|
|
254
|
+
logException(error, {
|
|
255
|
+
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager/getSyncBlockDataFromSessionStorage'
|
|
256
|
+
});
|
|
257
|
+
return undefined;
|
|
258
|
+
}
|
|
259
|
+
if (!sessionData) {
|
|
260
|
+
return undefined;
|
|
261
|
+
}
|
|
262
|
+
try {
|
|
263
|
+
return JSON.parse(sessionData);
|
|
264
|
+
} catch (error) {
|
|
265
|
+
logException(error, {
|
|
266
|
+
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager/getSyncBlockDataFromSessionStorage'
|
|
267
|
+
});
|
|
268
|
+
return undefined;
|
|
269
|
+
}
|
|
217
270
|
}
|
|
218
271
|
|
|
219
272
|
/**
|
|
@@ -318,13 +371,13 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
318
371
|
}, {
|
|
319
372
|
key: "setupGraphQLSubscription",
|
|
320
373
|
value: function setupGraphQLSubscription(resourceId) {
|
|
321
|
-
var _this$
|
|
374
|
+
var _this$dataProvider3,
|
|
322
375
|
_this4 = this;
|
|
323
376
|
// Don't set up duplicate subscriptions
|
|
324
377
|
if (this.graphqlSubscriptions.has(resourceId)) {
|
|
325
378
|
return;
|
|
326
379
|
}
|
|
327
|
-
if (!((_this$
|
|
380
|
+
if (!((_this$dataProvider3 = this.dataProvider) !== null && _this$dataProvider3 !== void 0 && _this$dataProvider3.subscribeToBlockUpdates)) {
|
|
328
381
|
return;
|
|
329
382
|
}
|
|
330
383
|
var unsubscribe = this.dataProvider.subscribeToBlockUpdates(resourceId, function (syncBlockInstance) {
|
|
@@ -767,8 +820,8 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
767
820
|
value: function updateCache(syncBlock) {
|
|
768
821
|
var resourceId = syncBlock.resourceId;
|
|
769
822
|
if (resourceId) {
|
|
770
|
-
var _this$
|
|
771
|
-
(_this$
|
|
823
|
+
var _this$dataProvider4;
|
|
824
|
+
(_this$dataProvider4 = this.dataProvider) === null || _this$dataProvider4 === void 0 || _this$dataProvider4.updateCache(_defineProperty({}, resourceId, syncBlock), {
|
|
772
825
|
strategy: 'merge',
|
|
773
826
|
source: 'network'
|
|
774
827
|
});
|
|
@@ -778,6 +831,9 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
778
831
|
callback(syncBlock);
|
|
779
832
|
});
|
|
780
833
|
}
|
|
834
|
+
if (fg('platform_synced_block_patch_3')) {
|
|
835
|
+
this.updateCacheInSessionStorage(resourceId);
|
|
836
|
+
}
|
|
781
837
|
}
|
|
782
838
|
}
|
|
783
839
|
}, {
|
|
@@ -793,15 +849,15 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
793
849
|
}, {
|
|
794
850
|
key: "getFromCache",
|
|
795
851
|
value: function getFromCache(resourceId) {
|
|
796
|
-
var _this$
|
|
852
|
+
var _this$dataProvider5;
|
|
797
853
|
var syncBlockNode = createSyncBlockNode('', resourceId);
|
|
798
|
-
return (_this$
|
|
854
|
+
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;
|
|
799
855
|
}
|
|
800
856
|
}, {
|
|
801
857
|
key: "deleteFromCache",
|
|
802
858
|
value: function deleteFromCache(resourceId) {
|
|
803
|
-
var _this$
|
|
804
|
-
(_this$
|
|
859
|
+
var _this$dataProvider6;
|
|
860
|
+
(_this$dataProvider6 = this.dataProvider) === null || _this$dataProvider6 === void 0 || _this$dataProvider6.removeFromCache([resourceId]);
|
|
805
861
|
this.providerFactories.delete(resourceId);
|
|
806
862
|
}
|
|
807
863
|
}, {
|
|
@@ -820,11 +876,22 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
820
876
|
this.scheduledBatchFetch();
|
|
821
877
|
}
|
|
822
878
|
}
|
|
879
|
+
}, {
|
|
880
|
+
key: "setSSRDataInSessionStorage",
|
|
881
|
+
value: function setSSRDataInSessionStorage(resourceIds) {
|
|
882
|
+
var _this0 = this;
|
|
883
|
+
if (!resourceIds || resourceIds.length === 0) {
|
|
884
|
+
return;
|
|
885
|
+
}
|
|
886
|
+
resourceIds.forEach(function (resourceId) {
|
|
887
|
+
_this0.updateCacheInSessionStorage(resourceId);
|
|
888
|
+
});
|
|
889
|
+
}
|
|
823
890
|
}, {
|
|
824
891
|
key: "subscribeToSyncBlock",
|
|
825
892
|
value: function subscribeToSyncBlock(resourceId, localId, callback) {
|
|
826
|
-
var _this$
|
|
827
|
-
|
|
893
|
+
var _this$dataProvider7,
|
|
894
|
+
_this1 = this;
|
|
828
895
|
// Cancel any pending cache deletion for this resourceId.
|
|
829
896
|
// This handles the case where a block is moved - the old component unmounts
|
|
830
897
|
// (scheduling deletion) but the new component mounts and subscribes before
|
|
@@ -850,7 +917,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
850
917
|
var syncBlockNode = createSyncBlockNode(localId, resourceId);
|
|
851
918
|
|
|
852
919
|
// call the callback immediately if we have cached data
|
|
853
|
-
var cachedData = (_this$
|
|
920
|
+
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;
|
|
854
921
|
if (cachedData) {
|
|
855
922
|
callback(cachedData);
|
|
856
923
|
} else {
|
|
@@ -862,19 +929,19 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
862
929
|
this.setupGraphQLSubscription(resourceId);
|
|
863
930
|
}
|
|
864
931
|
return function () {
|
|
865
|
-
var resourceSubscriptions =
|
|
932
|
+
var resourceSubscriptions = _this1.subscriptions.get(resourceId);
|
|
866
933
|
if (resourceSubscriptions) {
|
|
867
934
|
// Unsubscription means a reference synced block is removed from the document
|
|
868
|
-
|
|
935
|
+
_this1.isCacheDirty = true;
|
|
869
936
|
delete resourceSubscriptions[localId];
|
|
870
937
|
if (Object.keys(resourceSubscriptions).length === 0) {
|
|
871
|
-
|
|
938
|
+
_this1.subscriptions.delete(resourceId);
|
|
872
939
|
|
|
873
940
|
// Clean up GraphQL subscription when no more local subscribers
|
|
874
|
-
|
|
941
|
+
_this1.cleanupGraphQLSubscription(resourceId);
|
|
875
942
|
|
|
876
943
|
// Notify listeners that subscription was removed
|
|
877
|
-
|
|
944
|
+
_this1.notifySubscriptionChangeListeners();
|
|
878
945
|
|
|
879
946
|
// Delay cache deletion to handle block moves (unmount/remount).
|
|
880
947
|
// When a block is moved, the old component unmounts before the new one mounts.
|
|
@@ -883,14 +950,14 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
883
950
|
// TODO: EDITOR-4152 - Rework this logic
|
|
884
951
|
var deletionTimeout = setTimeout(function () {
|
|
885
952
|
// Only delete if still no subscribers (wasn't re-subscribed)
|
|
886
|
-
if (!
|
|
887
|
-
|
|
953
|
+
if (!_this1.subscriptions.has(resourceId)) {
|
|
954
|
+
_this1.deleteFromCache(resourceId);
|
|
888
955
|
}
|
|
889
|
-
|
|
956
|
+
_this1.pendingCacheDeletions.delete(resourceId);
|
|
890
957
|
}, 1000);
|
|
891
|
-
|
|
958
|
+
_this1.pendingCacheDeletions.set(resourceId, deletionTimeout);
|
|
892
959
|
} else {
|
|
893
|
-
|
|
960
|
+
_this1.subscriptions.set(resourceId, resourceSubscriptions);
|
|
894
961
|
}
|
|
895
962
|
}
|
|
896
963
|
};
|
|
@@ -899,7 +966,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
899
966
|
key: "subscribeToSourceTitle",
|
|
900
967
|
value: function subscribeToSourceTitle(node, callback) {
|
|
901
968
|
var _cachedData$data,
|
|
902
|
-
|
|
969
|
+
_this10 = this;
|
|
903
970
|
// check node is a sync block, as we only support sync block subscriptions
|
|
904
971
|
if (node.type.name !== 'syncBlock') {
|
|
905
972
|
return function () {};
|
|
@@ -919,13 +986,13 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
919
986
|
var resourceSubscriptions = this.titleSubscriptions.get(resourceId) || {};
|
|
920
987
|
this.titleSubscriptions.set(resourceId, _objectSpread(_objectSpread({}, resourceSubscriptions), {}, _defineProperty({}, localId, callback)));
|
|
921
988
|
return function () {
|
|
922
|
-
var resourceSubscriptions =
|
|
989
|
+
var resourceSubscriptions = _this10.titleSubscriptions.get(resourceId);
|
|
923
990
|
if (resourceSubscriptions) {
|
|
924
991
|
delete resourceSubscriptions[localId];
|
|
925
992
|
if (Object.keys(resourceSubscriptions).length === 0) {
|
|
926
|
-
|
|
993
|
+
_this10.titleSubscriptions.delete(resourceId);
|
|
927
994
|
} else {
|
|
928
|
-
|
|
995
|
+
_this10.titleSubscriptions.set(resourceId, resourceSubscriptions);
|
|
929
996
|
}
|
|
930
997
|
}
|
|
931
998
|
};
|
|
@@ -1120,7 +1187,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
1120
1187
|
key: "flush",
|
|
1121
1188
|
value: (function () {
|
|
1122
1189
|
var _flush = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
|
|
1123
|
-
var
|
|
1190
|
+
var _this11 = this;
|
|
1124
1191
|
var success, syncedBlocksToFlush, _this$saveExperience, blocks, _iterator4, _step4, _loop2, updateResult, _this$saveExperience2, _this$fireAnalyticsEv1, _this$saveExperience3, _this$fireAnalyticsEv10, _this$saveExperience4;
|
|
1125
1192
|
return _regeneratorRuntime.wrap(function _callee4$(_context6) {
|
|
1126
1193
|
while (1) switch (_context6.prev = _context6.next) {
|
|
@@ -1282,8 +1349,8 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
1282
1349
|
// Use setTimeout to avoid deep recursion and run queued flush asynchronously
|
|
1283
1350
|
// Note: flush() handles all exceptions internally and never rejects
|
|
1284
1351
|
this.queuedFlushTimeout = setTimeout(function () {
|
|
1285
|
-
|
|
1286
|
-
void
|
|
1352
|
+
_this11.queuedFlushTimeout = undefined;
|
|
1353
|
+
void _this11.flush();
|
|
1287
1354
|
}, 0);
|
|
1288
1355
|
}
|
|
1289
1356
|
}
|
|
@@ -1304,7 +1371,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
1304
1371
|
}, {
|
|
1305
1372
|
key: "destroy",
|
|
1306
1373
|
value: function destroy() {
|
|
1307
|
-
var _this$
|
|
1374
|
+
var _this$dataProvider8, _this$saveExperience5, _this$fetchExperience0, _this$fetchSourceInfo2;
|
|
1308
1375
|
// Cancel any queued flush to prevent it from running after destroy
|
|
1309
1376
|
if (this.queuedFlushTimeout) {
|
|
1310
1377
|
clearTimeout(this.queuedFlushTimeout);
|
|
@@ -1313,7 +1380,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
1313
1380
|
|
|
1314
1381
|
// Clean up all GraphQL subscriptions first
|
|
1315
1382
|
this.cleanupAllGraphQLSubscriptions();
|
|
1316
|
-
(_this$
|
|
1383
|
+
(_this$dataProvider8 = this.dataProvider) === null || _this$dataProvider8 === void 0 || _this$dataProvider8.resetCache();
|
|
1317
1384
|
this.scheduledBatchFetch.cancel();
|
|
1318
1385
|
this.pendingFetchRequests.clear();
|
|
1319
1386
|
this.dataProvider = undefined;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export { useMemoizedBlockServiceAPIProviders, useMemoizedBlockServiceFetchOnlyAP
|
|
|
12
12
|
export { fetchConfluencePageInfo } from './clients/confluence/sourceInfo';
|
|
13
13
|
export { SyncBlockProvider as SyncedBlockProvider, useMemoizedSyncedBlockProvider, } from './providers/syncBlockProvider';
|
|
14
14
|
export type { ADFFetchProvider, ADFWriteProvider, BlockNodeIdentifiers, BlockSubscriptionErrorCallback, BlockUpdateCallback, SyncBlockDataProvider, SyncBlockInstance, MediaEmojiProviderOptions, SyncedBlockRendererProviderOptions, SyncBlockRendererProviderCreator, SyncedBlockRendererDataProviders, Unsubscribe, UpdateReferenceSyncBlockResult, WriteSyncBlockResult, SyncBlockParentInfo, SyncBlockSourceInfo, } from './providers/types';
|
|
15
|
-
export {
|
|
15
|
+
export { ReferenceSyncBlockStoreManager } from './store-manager/referenceSyncBlockStoreManager';
|
|
16
16
|
export { SyncBlockStoreManager, useMemoizedSyncBlockStoreManager, } from './store-manager/syncBlockStoreManager';
|
|
17
17
|
export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
|
|
18
18
|
export { parseResourceId, createResourceIdForReference } from './utils/resourceId';
|
|
@@ -73,6 +73,8 @@ export declare class ReferenceSyncBlockStoreManager {
|
|
|
73
73
|
generateResourceIdForReference(sourceId: ResourceId): ResourceId;
|
|
74
74
|
updateFireAnalyticsEvent(fireAnalyticsEvent?: (payload: RendererSyncBlockEventPayload) => void): void;
|
|
75
75
|
getInitialSyncBlockData(resourceId: ResourceId): SyncBlockInstance | undefined;
|
|
76
|
+
private updateCacheInSessionStorage;
|
|
77
|
+
private getSyncBlockDataFromSessionStorage;
|
|
76
78
|
/**
|
|
77
79
|
* Refreshes the subscriptions for all sync blocks.
|
|
78
80
|
* This is a fallback polling mechanism when real-time subscriptions are not enabled.
|
|
@@ -123,6 +125,7 @@ export declare class ReferenceSyncBlockStoreManager {
|
|
|
123
125
|
getFromCache(resourceId: ResourceId): SyncBlockInstance | undefined;
|
|
124
126
|
private deleteFromCache;
|
|
125
127
|
private debouncedBatchedFetchSyncBlocks;
|
|
128
|
+
private setSSRDataInSessionStorage;
|
|
126
129
|
subscribeToSyncBlock(resourceId: string, localId: string, callback: SubscriptionCallback): () => void;
|
|
127
130
|
subscribeToSourceTitle(node: PMNode, callback: TitleSubscriptionCallback): () => void;
|
|
128
131
|
subscribe(node: PMNode, callback: SubscriptionCallback): () => void;
|
|
@@ -12,7 +12,7 @@ export { useMemoizedBlockServiceAPIProviders, useMemoizedBlockServiceFetchOnlyAP
|
|
|
12
12
|
export { fetchConfluencePageInfo } from './clients/confluence/sourceInfo';
|
|
13
13
|
export { SyncBlockProvider as SyncedBlockProvider, useMemoizedSyncedBlockProvider, } from './providers/syncBlockProvider';
|
|
14
14
|
export type { ADFFetchProvider, ADFWriteProvider, BlockNodeIdentifiers, BlockSubscriptionErrorCallback, BlockUpdateCallback, SyncBlockDataProvider, SyncBlockInstance, MediaEmojiProviderOptions, SyncedBlockRendererProviderOptions, SyncBlockRendererProviderCreator, SyncedBlockRendererDataProviders, Unsubscribe, UpdateReferenceSyncBlockResult, WriteSyncBlockResult, SyncBlockParentInfo, SyncBlockSourceInfo, } from './providers/types';
|
|
15
|
-
export {
|
|
15
|
+
export { ReferenceSyncBlockStoreManager } from './store-manager/referenceSyncBlockStoreManager';
|
|
16
16
|
export { SyncBlockStoreManager, useMemoizedSyncBlockStoreManager, } from './store-manager/syncBlockStoreManager';
|
|
17
17
|
export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
|
|
18
18
|
export { parseResourceId, createResourceIdForReference } from './utils/resourceId';
|
|
@@ -73,6 +73,8 @@ export declare class ReferenceSyncBlockStoreManager {
|
|
|
73
73
|
generateResourceIdForReference(sourceId: ResourceId): ResourceId;
|
|
74
74
|
updateFireAnalyticsEvent(fireAnalyticsEvent?: (payload: RendererSyncBlockEventPayload) => void): void;
|
|
75
75
|
getInitialSyncBlockData(resourceId: ResourceId): SyncBlockInstance | undefined;
|
|
76
|
+
private updateCacheInSessionStorage;
|
|
77
|
+
private getSyncBlockDataFromSessionStorage;
|
|
76
78
|
/**
|
|
77
79
|
* Refreshes the subscriptions for all sync blocks.
|
|
78
80
|
* This is a fallback polling mechanism when real-time subscriptions are not enabled.
|
|
@@ -123,6 +125,7 @@ export declare class ReferenceSyncBlockStoreManager {
|
|
|
123
125
|
getFromCache(resourceId: ResourceId): SyncBlockInstance | undefined;
|
|
124
126
|
private deleteFromCache;
|
|
125
127
|
private debouncedBatchedFetchSyncBlocks;
|
|
128
|
+
private setSSRDataInSessionStorage;
|
|
126
129
|
subscribeToSyncBlock(resourceId: string, localId: string, callback: SubscriptionCallback): () => void;
|
|
127
130
|
subscribeToSourceTitle(node: PMNode, callback: TitleSubscriptionCallback): () => void;
|
|
128
131
|
subscribe(node: PMNode, callback: SubscriptionCallback): () => void;
|
package/package.json
CHANGED
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"uuid": "^3.1.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"@atlaskit/editor-common": "^111.
|
|
40
|
+
"@atlaskit/editor-common": "^111.14.0",
|
|
41
41
|
"react": "^18.2.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
}
|
|
81
81
|
},
|
|
82
82
|
"name": "@atlaskit/editor-synced-block-provider",
|
|
83
|
-
"version": "3.29.
|
|
83
|
+
"version": "3.29.1",
|
|
84
84
|
"description": "Synced Block Provider for @atlaskit/editor-plugin-synced-block",
|
|
85
85
|
"author": "Atlassian Pty Ltd",
|
|
86
86
|
"license": "Apache-2.0",
|
|
@@ -90,6 +90,9 @@
|
|
|
90
90
|
"platform-feature-flags": {
|
|
91
91
|
"platform_synced_block_patch_2": {
|
|
92
92
|
"type": "boolean"
|
|
93
|
+
},
|
|
94
|
+
"platform_synced_block_patch_3": {
|
|
95
|
+
"type": "boolean"
|
|
93
96
|
}
|
|
94
97
|
}
|
|
95
98
|
}
|