@atlaskit/editor-synced-block-provider 4.1.0 → 4.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +209 -811
- package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +3 -6
- package/dist/cjs/store-manager/syncBlockSubscriptionManager.js +180 -17
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +78 -595
- package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +3 -6
- package/dist/es2019/store-manager/syncBlockSubscriptionManager.js +157 -10
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +210 -812
- package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +3 -6
- package/dist/esm/store-manager/syncBlockSubscriptionManager.js +180 -17
- package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +4 -49
- package/dist/types/store-manager/syncBlockSubscriptionManager.d.ts +25 -6
- package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +4 -49
- package/dist/types-ts4.5/store-manager/syncBlockSubscriptionManager.d.ts +25 -6
- package/package.json +4 -8
|
@@ -7,7 +7,6 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
7
7
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
8
8
|
import isEqual from 'lodash/isEqual';
|
|
9
9
|
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
10
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
11
10
|
import { SyncBlockError } from '../common/types';
|
|
12
11
|
import { updateErrorPayload, createErrorPayload, deleteErrorPayload, updateCacheErrorPayload, getSourceInfoErrorPayload, updateSuccessPayload, createSuccessPayload, deleteSuccessPayload, fetchReferencesErrorPayload } from '../utils/errorHandling';
|
|
13
12
|
import { getCreateSourceExperience, getDeleteSourceExperience, getSaveSourceExperience, getFetchSourceInfoExperience } from '../utils/experienceTracking';
|
|
@@ -65,11 +64,9 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
65
64
|
throw new Error('Local ID or resource ID is not set');
|
|
66
65
|
}
|
|
67
66
|
var syncBlockData = convertSyncBlockPMNodeToSyncBlockData(syncBlockNode);
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
this.hasReceivedContentChange = true;
|
|
72
|
-
}
|
|
67
|
+
var cachedBlock = this.syncBlockCache.get(resourceId);
|
|
68
|
+
if (cachedBlock && !isEqual(syncBlockData.content, cachedBlock.content)) {
|
|
69
|
+
this.hasReceivedContentChange = true;
|
|
73
70
|
}
|
|
74
71
|
this.syncBlockCache.set(resourceId, _objectSpread(_objectSpread({}, syncBlockData), {}, {
|
|
75
72
|
isDirty: true
|
|
@@ -4,24 +4,43 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
|
4
4
|
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; } } }; }
|
|
5
5
|
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; } }
|
|
6
6
|
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; }
|
|
7
|
+
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; }
|
|
8
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7
9
|
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
8
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
9
10
|
import { fetchErrorPayload, fetchSuccessPayload } from '../utils/errorHandling';
|
|
10
11
|
import { resolveSyncBlockInstance } from '../utils/resolveSyncBlockInstance';
|
|
11
12
|
/**
|
|
12
13
|
* Manages the lifecycle of GraphQL WebSocket subscriptions for sync block
|
|
13
|
-
* real-time updates,
|
|
14
|
-
*
|
|
14
|
+
* real-time updates, owns the subscriptions and titleSubscriptions maps,
|
|
15
|
+
* and provides a listener API so React components can react when the set
|
|
16
|
+
* of subscribed resource IDs changes.
|
|
15
17
|
*/
|
|
16
18
|
export var SyncBlockSubscriptionManager = /*#__PURE__*/function () {
|
|
17
19
|
function SyncBlockSubscriptionManager(deps) {
|
|
18
20
|
_classCallCheck(this, SyncBlockSubscriptionManager);
|
|
21
|
+
_defineProperty(this, "subscriptions", new Map());
|
|
22
|
+
_defineProperty(this, "titleSubscriptions", new Map());
|
|
19
23
|
_defineProperty(this, "graphqlSubscriptions", new Map());
|
|
20
24
|
_defineProperty(this, "subscriptionChangeListeners", new Set());
|
|
21
25
|
_defineProperty(this, "useRealTimeSubscriptions", false);
|
|
26
|
+
// Track pending cache deletions to handle block moves (unmount/remount)
|
|
27
|
+
// When a block is moved, the old component unmounts before the new one mounts,
|
|
28
|
+
// causing the cache to be deleted prematurely. We delay deletion to allow
|
|
29
|
+
// the new component to subscribe and cancel the pending deletion.
|
|
30
|
+
_defineProperty(this, "pendingCacheDeletions", new Map());
|
|
22
31
|
this.deps = deps;
|
|
23
32
|
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Returns the subscriptions map. Used by external consumers (e.g. batch fetcher, flush)
|
|
36
|
+
* that need to read the current subscription state.
|
|
37
|
+
*/
|
|
24
38
|
return _createClass(SyncBlockSubscriptionManager, [{
|
|
39
|
+
key: "getSubscriptions",
|
|
40
|
+
value: function getSubscriptions() {
|
|
41
|
+
return this.subscriptions;
|
|
42
|
+
}
|
|
43
|
+
}, {
|
|
25
44
|
key: "setRealTimeSubscriptionsEnabled",
|
|
26
45
|
value: function setRealTimeSubscriptionsEnabled(enabled) {
|
|
27
46
|
if (this.useRealTimeSubscriptions === enabled) {
|
|
@@ -42,7 +61,7 @@ export var SyncBlockSubscriptionManager = /*#__PURE__*/function () {
|
|
|
42
61
|
}, {
|
|
43
62
|
key: "getSubscribedResourceIds",
|
|
44
63
|
value: function getSubscribedResourceIds() {
|
|
45
|
-
return Array.from(this.
|
|
64
|
+
return Array.from(this.subscriptions.keys());
|
|
46
65
|
}
|
|
47
66
|
}, {
|
|
48
67
|
key: "onSubscriptionsChanged",
|
|
@@ -82,10 +101,140 @@ export var SyncBlockSubscriptionManager = /*#__PURE__*/function () {
|
|
|
82
101
|
this.deps.fetchSyncBlockSourceInfo(resolved.resourceId);
|
|
83
102
|
}
|
|
84
103
|
}
|
|
104
|
+
}, {
|
|
105
|
+
key: "subscribeToSyncBlock",
|
|
106
|
+
value: function subscribeToSyncBlock(resourceId, localId, callback) {
|
|
107
|
+
var _this3 = this;
|
|
108
|
+
// Cancel any pending cache deletion for this resourceId.
|
|
109
|
+
// This handles the case where a block is moved - the old component unmounts
|
|
110
|
+
// (scheduling deletion) but the new component mounts and subscribes before
|
|
111
|
+
// the deletion timeout fires.
|
|
112
|
+
var pendingDeletion = this.pendingCacheDeletions.get(resourceId);
|
|
113
|
+
if (pendingDeletion) {
|
|
114
|
+
clearTimeout(pendingDeletion);
|
|
115
|
+
this.pendingCacheDeletions.delete(resourceId);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// add to subscriptions map
|
|
119
|
+
var resourceSubscriptions = this.subscriptions.get(resourceId) || {};
|
|
120
|
+
var isNewResourceSubscription = Object.keys(resourceSubscriptions).length === 0;
|
|
121
|
+
this.subscriptions.set(resourceId, _objectSpread(_objectSpread({}, resourceSubscriptions), {}, _defineProperty({}, localId, callback)));
|
|
122
|
+
|
|
123
|
+
// New subscription means new reference synced block is added to the document
|
|
124
|
+
this.deps.markCacheDirty();
|
|
125
|
+
|
|
126
|
+
// Notify listeners if this is a new resource subscription
|
|
127
|
+
if (isNewResourceSubscription) {
|
|
128
|
+
this.notifySubscriptionChangeListeners();
|
|
129
|
+
}
|
|
130
|
+
var cachedData = this.deps.getFromCache(resourceId);
|
|
131
|
+
if (cachedData) {
|
|
132
|
+
callback(cachedData);
|
|
133
|
+
} else {
|
|
134
|
+
this.deps.debouncedBatchedFetchSyncBlocks(resourceId);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Set up GraphQL subscription if real-time subscriptions are enabled
|
|
138
|
+
if (this.shouldUseRealTime()) {
|
|
139
|
+
this.setupSubscription(resourceId);
|
|
140
|
+
}
|
|
141
|
+
return function () {
|
|
142
|
+
var resourceSubscriptions = _this3.subscriptions.get(resourceId);
|
|
143
|
+
if (resourceSubscriptions) {
|
|
144
|
+
// Unsubscription means a reference synced block is removed from the document
|
|
145
|
+
_this3.deps.markCacheDirty();
|
|
146
|
+
delete resourceSubscriptions[localId];
|
|
147
|
+
if (Object.keys(resourceSubscriptions).length === 0) {
|
|
148
|
+
_this3.subscriptions.delete(resourceId);
|
|
149
|
+
|
|
150
|
+
// Clean up GraphQL subscription when no more local subscribers
|
|
151
|
+
_this3.cleanupSubscription(resourceId);
|
|
152
|
+
|
|
153
|
+
// Notify listeners that subscription was removed
|
|
154
|
+
_this3.notifySubscriptionChangeListeners();
|
|
155
|
+
|
|
156
|
+
// Delay cache deletion to handle block moves (unmount/remount).
|
|
157
|
+
// When a block is moved, the old component unmounts before the new one mounts.
|
|
158
|
+
// By delaying deletion, we give the new component time to subscribe and
|
|
159
|
+
// cancel this pending deletion, preserving the cached data.
|
|
160
|
+
// TODO: EDITOR-4152 - Rework this logic
|
|
161
|
+
var deletionTimeout = setTimeout(function () {
|
|
162
|
+
// Only delete if still no subscribers (wasn't re-subscribed)
|
|
163
|
+
if (!_this3.subscriptions.has(resourceId)) {
|
|
164
|
+
_this3.deps.deleteFromCache(resourceId);
|
|
165
|
+
}
|
|
166
|
+
_this3.pendingCacheDeletions.delete(resourceId);
|
|
167
|
+
}, 1000);
|
|
168
|
+
_this3.pendingCacheDeletions.set(resourceId, deletionTimeout);
|
|
169
|
+
} else {
|
|
170
|
+
_this3.subscriptions.set(resourceId, resourceSubscriptions);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
}, {
|
|
176
|
+
key: "subscribeToSourceTitle",
|
|
177
|
+
value: function subscribeToSourceTitle(node, callback) {
|
|
178
|
+
var _cachedData$data,
|
|
179
|
+
_this4 = this;
|
|
180
|
+
// check node is a sync block, as we only support sync block subscriptions
|
|
181
|
+
if (node.type.name !== 'syncBlock') {
|
|
182
|
+
return function () {};
|
|
183
|
+
}
|
|
184
|
+
var _node$attrs = node.attrs,
|
|
185
|
+
resourceId = _node$attrs.resourceId,
|
|
186
|
+
localId = _node$attrs.localId;
|
|
187
|
+
if (!localId || !resourceId) {
|
|
188
|
+
return function () {};
|
|
189
|
+
}
|
|
190
|
+
var cachedData = this.deps.getFromCache(resourceId);
|
|
191
|
+
if (cachedData !== null && cachedData !== void 0 && (_cachedData$data = cachedData.data) !== null && _cachedData$data !== void 0 && _cachedData$data.sourceTitle) {
|
|
192
|
+
callback(cachedData.data.sourceTitle);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// add to subscriptions map
|
|
196
|
+
var resourceSubscriptions = this.titleSubscriptions.get(resourceId) || {};
|
|
197
|
+
this.titleSubscriptions.set(resourceId, _objectSpread(_objectSpread({}, resourceSubscriptions), {}, _defineProperty({}, localId, callback)));
|
|
198
|
+
return function () {
|
|
199
|
+
var resourceSubscriptions = _this4.titleSubscriptions.get(resourceId);
|
|
200
|
+
if (resourceSubscriptions) {
|
|
201
|
+
delete resourceSubscriptions[localId];
|
|
202
|
+
if (Object.keys(resourceSubscriptions).length === 0) {
|
|
203
|
+
_this4.titleSubscriptions.delete(resourceId);
|
|
204
|
+
} else {
|
|
205
|
+
_this4.titleSubscriptions.set(resourceId, resourceSubscriptions);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
}, {
|
|
211
|
+
key: "updateSourceTitleSubscriptions",
|
|
212
|
+
value: function updateSourceTitleSubscriptions(resourceId, title) {
|
|
213
|
+
var callbacks = this.titleSubscriptions.get(resourceId);
|
|
214
|
+
if (callbacks) {
|
|
215
|
+
Object.values(callbacks).forEach(function (callback) {
|
|
216
|
+
callback(title);
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Notifies all subscription callbacks for a given resource ID with the provided sync block instance.
|
|
223
|
+
*/
|
|
224
|
+
}, {
|
|
225
|
+
key: "notifySubscriptionCallbacks",
|
|
226
|
+
value: function notifySubscriptionCallbacks(resourceId, syncBlock) {
|
|
227
|
+
var callbacks = this.subscriptions.get(resourceId);
|
|
228
|
+
if (callbacks) {
|
|
229
|
+
Object.values(callbacks).forEach(function (callback) {
|
|
230
|
+
callback(syncBlock);
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}
|
|
85
234
|
}, {
|
|
86
235
|
key: "setupSubscription",
|
|
87
236
|
value: function setupSubscription(resourceId) {
|
|
88
|
-
var
|
|
237
|
+
var _this5 = this;
|
|
89
238
|
if (this.graphqlSubscriptions.has(resourceId)) {
|
|
90
239
|
return;
|
|
91
240
|
}
|
|
@@ -94,13 +243,13 @@ export var SyncBlockSubscriptionManager = /*#__PURE__*/function () {
|
|
|
94
243
|
return;
|
|
95
244
|
}
|
|
96
245
|
var unsubscribe = dataProvider.subscribeToBlockUpdates(resourceId, function (syncBlockInstance) {
|
|
97
|
-
|
|
246
|
+
_this5.handleGraphQLUpdate(syncBlockInstance);
|
|
98
247
|
}, function (error) {
|
|
99
|
-
var
|
|
248
|
+
var _this5$deps$getFireAn;
|
|
100
249
|
logException(error, {
|
|
101
250
|
location: 'editor-synced-block-provider/syncBlockSubscriptionManager/graphql-subscription'
|
|
102
251
|
});
|
|
103
|
-
(
|
|
252
|
+
(_this5$deps$getFireAn = _this5.deps.getFireAnalyticsEvent()) === null || _this5$deps$getFireAn === void 0 || _this5$deps$getFireAn(fetchErrorPayload(error.message));
|
|
104
253
|
});
|
|
105
254
|
if (unsubscribe) {
|
|
106
255
|
this.graphqlSubscriptions.set(resourceId, unsubscribe);
|
|
@@ -118,7 +267,7 @@ export var SyncBlockSubscriptionManager = /*#__PURE__*/function () {
|
|
|
118
267
|
}, {
|
|
119
268
|
key: "setupSubscriptionsForAllBlocks",
|
|
120
269
|
value: function setupSubscriptionsForAllBlocks() {
|
|
121
|
-
var _iterator = _createForOfIteratorHelper(this.
|
|
270
|
+
var _iterator = _createForOfIteratorHelper(this.subscriptions.keys()),
|
|
122
271
|
_step;
|
|
123
272
|
try {
|
|
124
273
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
@@ -152,8 +301,25 @@ export var SyncBlockSubscriptionManager = /*#__PURE__*/function () {
|
|
|
152
301
|
key: "destroy",
|
|
153
302
|
value: function destroy() {
|
|
154
303
|
this.cleanupAll();
|
|
304
|
+
this.subscriptions.clear();
|
|
305
|
+
this.titleSubscriptions.clear();
|
|
155
306
|
this.subscriptionChangeListeners.clear();
|
|
156
307
|
this.useRealTimeSubscriptions = false;
|
|
308
|
+
|
|
309
|
+
// Clear any pending cache deletions
|
|
310
|
+
var _iterator3 = _createForOfIteratorHelper(this.pendingCacheDeletions.values()),
|
|
311
|
+
_step3;
|
|
312
|
+
try {
|
|
313
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
314
|
+
var timeout = _step3.value;
|
|
315
|
+
clearTimeout(timeout);
|
|
316
|
+
}
|
|
317
|
+
} catch (err) {
|
|
318
|
+
_iterator3.e(err);
|
|
319
|
+
} finally {
|
|
320
|
+
_iterator3.f();
|
|
321
|
+
}
|
|
322
|
+
this.pendingCacheDeletions.clear();
|
|
157
323
|
}
|
|
158
324
|
}, {
|
|
159
325
|
key: "shouldUseRealTime",
|
|
@@ -163,22 +329,19 @@ export var SyncBlockSubscriptionManager = /*#__PURE__*/function () {
|
|
|
163
329
|
}, {
|
|
164
330
|
key: "handleGraphQLUpdate",
|
|
165
331
|
value: function handleGraphQLUpdate(syncBlockInstance) {
|
|
166
|
-
var
|
|
332
|
+
var _this6 = this;
|
|
167
333
|
if (!syncBlockInstance.resourceId) {
|
|
168
|
-
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
throw new Error('Sync block instance provided to graphql subscription update missing resource id');
|
|
334
|
+
return;
|
|
172
335
|
}
|
|
173
336
|
var existing = this.deps.getFromCache(syncBlockInstance.resourceId);
|
|
174
337
|
var resolved = existing ? resolveSyncBlockInstance(existing, syncBlockInstance) : syncBlockInstance;
|
|
175
338
|
this.deps.updateCache(resolved);
|
|
176
339
|
if (!syncBlockInstance.error) {
|
|
177
|
-
var callbacks = this.
|
|
340
|
+
var callbacks = this.subscriptions.get(syncBlockInstance.resourceId);
|
|
178
341
|
var localIds = callbacks ? Object.keys(callbacks) : [];
|
|
179
342
|
localIds.forEach(function (localId) {
|
|
180
|
-
var
|
|
181
|
-
(
|
|
343
|
+
var _this6$deps$getFireAn, _syncBlockInstance$da;
|
|
344
|
+
(_this6$deps$getFireAn = _this6.deps.getFireAnalyticsEvent()) === null || _this6$deps$getFireAn === void 0 || _this6$deps$getFireAn(fetchSuccessPayload(syncBlockInstance.resourceId, localId, (_syncBlockInstance$da = syncBlockInstance.data) === null || _syncBlockInstance$da === void 0 ? void 0 : _syncBlockInstance$da.product));
|
|
182
345
|
});
|
|
183
346
|
this.deps.fetchSyncBlockSourceInfo(resolved.resourceId);
|
|
184
347
|
} else {
|
|
@@ -1,23 +1,15 @@
|
|
|
1
1
|
import { type RendererSyncBlockEventPayload } from '@atlaskit/editor-common/analytics';
|
|
2
2
|
import type { Experience } from '@atlaskit/editor-common/experiences';
|
|
3
|
-
import { ProviderFactory, type MediaProvider } from '@atlaskit/editor-common/provider-factory';
|
|
3
|
+
import { type ProviderFactory, type MediaProvider } from '@atlaskit/editor-common/provider-factory';
|
|
4
4
|
import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
5
5
|
import { type ResourceId, type SyncBlockNode, type SyncBlockPrefetchData } from '../common/types';
|
|
6
6
|
import type { SyncBlockInstance, SubscriptionCallback, SyncBlockDataProviderInterface, TitleSubscriptionCallback, SyncBlockSourceInfo } from '../providers/types';
|
|
7
7
|
export declare class ReferenceSyncBlockStoreManager {
|
|
8
8
|
private dataProvider?;
|
|
9
9
|
private isCacheDirty;
|
|
10
|
-
private subscriptions;
|
|
11
|
-
private titleSubscriptions;
|
|
12
|
-
private providerFactories;
|
|
13
10
|
private fireAnalyticsEvent?;
|
|
14
11
|
private syncBlockFetchDataRequests;
|
|
15
12
|
private syncBlockSourceInfoRequests;
|
|
16
|
-
private isRefreshingSubscriptions;
|
|
17
|
-
private pendingCacheDeletions;
|
|
18
|
-
private graphqlSubscriptions;
|
|
19
|
-
private useRealTimeSubscriptions;
|
|
20
|
-
private subscriptionChangeListeners;
|
|
21
13
|
private newlyAddedSyncBlocks;
|
|
22
14
|
private lastFlushedSyncedBlocks;
|
|
23
15
|
private onUnpublishedSyncBlockDetected?;
|
|
@@ -27,11 +19,9 @@ export declare class ReferenceSyncBlockStoreManager {
|
|
|
27
19
|
fetchExperience: Experience | undefined;
|
|
28
20
|
private fetchSourceInfoExperience;
|
|
29
21
|
private saveExperience;
|
|
30
|
-
private _subscriptionManager
|
|
31
|
-
private _providerFactoryManager
|
|
32
|
-
private _batchFetcher
|
|
33
|
-
private pendingFetchRequests;
|
|
34
|
-
private scheduledBatchFetch;
|
|
22
|
+
private _subscriptionManager;
|
|
23
|
+
private _providerFactoryManager;
|
|
24
|
+
private _batchFetcher;
|
|
35
25
|
constructor(dataProvider?: SyncBlockDataProviderInterface);
|
|
36
26
|
/**
|
|
37
27
|
* Enables or disables real-time GraphQL subscriptions for block updates.
|
|
@@ -55,10 +45,6 @@ export declare class ReferenceSyncBlockStoreManager {
|
|
|
55
45
|
* @returns Unsubscribe function to remove the listener
|
|
56
46
|
*/
|
|
57
47
|
onSubscriptionsChanged(listener: () => void): () => void;
|
|
58
|
-
/**
|
|
59
|
-
* Notifies all subscription change listeners.
|
|
60
|
-
*/
|
|
61
|
-
private notifySubscriptionChangeListeners;
|
|
62
48
|
/**
|
|
63
49
|
* Handles incoming data from a GraphQL subscription.
|
|
64
50
|
* Called by React subscription components when they receive updates.
|
|
@@ -78,35 +64,6 @@ export declare class ReferenceSyncBlockStoreManager {
|
|
|
78
64
|
getInitialSyncBlockData(resourceId: ResourceId): SyncBlockInstance | undefined;
|
|
79
65
|
private updateSessionCache;
|
|
80
66
|
private getFromSessionCache;
|
|
81
|
-
/**
|
|
82
|
-
* Refreshes the subscriptions for all sync blocks.
|
|
83
|
-
* This is a fallback polling mechanism when real-time subscriptions are not enabled.
|
|
84
|
-
* @returns {Promise<void>}
|
|
85
|
-
*/
|
|
86
|
-
refreshSubscriptions(): Promise<void>;
|
|
87
|
-
/**
|
|
88
|
-
* Sets up a GraphQL subscription for a specific block.
|
|
89
|
-
* @param resourceId - The resource ID of the block to subscribe to
|
|
90
|
-
*/
|
|
91
|
-
private setupGraphQLSubscription;
|
|
92
|
-
/**
|
|
93
|
-
* Handles updates received from GraphQL subscriptions.
|
|
94
|
-
* @param syncBlockInstance - The updated sync block instance
|
|
95
|
-
*/
|
|
96
|
-
private handleGraphQLSubscriptionUpdate;
|
|
97
|
-
/**
|
|
98
|
-
* Cleans up the GraphQL subscription for a specific block.
|
|
99
|
-
* @param resourceId - The resource ID of the block to unsubscribe from
|
|
100
|
-
*/
|
|
101
|
-
private cleanupGraphQLSubscription;
|
|
102
|
-
/**
|
|
103
|
-
* Sets up GraphQL subscriptions for all currently subscribed blocks.
|
|
104
|
-
*/
|
|
105
|
-
private setupGraphQLSubscriptionsForAllBlocks;
|
|
106
|
-
/**
|
|
107
|
-
* Cleans up all GraphQL subscriptions.
|
|
108
|
-
*/
|
|
109
|
-
private cleanupAllGraphQLSubscriptions;
|
|
110
67
|
fetchSyncBlockSourceInfoBySourceAri(sourceAri: string, hasAccess?: boolean): Promise<SyncBlockSourceInfo | undefined>;
|
|
111
68
|
fetchSyncBlockSourceInfo(resourceId: ResourceId): Promise<SyncBlockSourceInfo | undefined>;
|
|
112
69
|
/**
|
|
@@ -124,7 +81,6 @@ export declare class ReferenceSyncBlockStoreManager {
|
|
|
124
81
|
private processFetchedData;
|
|
125
82
|
private updateCacheWithSourceInfo;
|
|
126
83
|
private updateCache;
|
|
127
|
-
private updateSourceTitleSubscriptions;
|
|
128
84
|
getFromCache(resourceId: ResourceId): SyncBlockInstance | undefined;
|
|
129
85
|
private deleteFromCache;
|
|
130
86
|
private debouncedBatchedFetchSyncBlocks;
|
|
@@ -142,7 +98,6 @@ export declare class ReferenceSyncBlockStoreManager {
|
|
|
142
98
|
getSSRProviders(resourceId: ResourceId): {
|
|
143
99
|
media: MediaProvider;
|
|
144
100
|
} | null;
|
|
145
|
-
private retrieveDynamicProviders;
|
|
146
101
|
/**
|
|
147
102
|
* Update reference synced blocks on the document with the BE
|
|
148
103
|
*
|
|
@@ -1,33 +1,52 @@
|
|
|
1
1
|
import { type RendererSyncBlockEventPayload } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
3
|
import type { ResourceId, BlockInstanceId } from '../common/types';
|
|
3
|
-
import type { SyncBlockInstance, SubscriptionCallback, SyncBlockDataProviderInterface, SyncBlockSourceInfo } from '../providers/types';
|
|
4
|
+
import type { SyncBlockInstance, SubscriptionCallback, SyncBlockDataProviderInterface, SyncBlockSourceInfo, TitleSubscriptionCallback } from '../providers/types';
|
|
4
5
|
export interface SyncBlockSubscriptionManagerDeps {
|
|
6
|
+
debouncedBatchedFetchSyncBlocks: (resourceId: string) => void;
|
|
7
|
+
deleteFromCache: (resourceId: ResourceId) => void;
|
|
5
8
|
fetchSyncBlockSourceInfo: (resourceId: ResourceId) => Promise<SyncBlockSourceInfo | undefined>;
|
|
6
9
|
getDataProvider: () => SyncBlockDataProviderInterface | undefined;
|
|
7
10
|
getFireAnalyticsEvent: () => ((payload: RendererSyncBlockEventPayload) => void) | undefined;
|
|
8
11
|
getFromCache: (resourceId: ResourceId) => SyncBlockInstance | undefined;
|
|
9
|
-
|
|
10
|
-
[localId: BlockInstanceId]: SubscriptionCallback;
|
|
11
|
-
}>;
|
|
12
|
+
markCacheDirty: () => void;
|
|
12
13
|
updateCache: (syncBlockInstance: SyncBlockInstance) => void;
|
|
13
14
|
}
|
|
14
15
|
/**
|
|
15
16
|
* Manages the lifecycle of GraphQL WebSocket subscriptions for sync block
|
|
16
|
-
* real-time updates,
|
|
17
|
-
*
|
|
17
|
+
* real-time updates, owns the subscriptions and titleSubscriptions maps,
|
|
18
|
+
* and provides a listener API so React components can react when the set
|
|
19
|
+
* of subscribed resource IDs changes.
|
|
18
20
|
*/
|
|
19
21
|
export declare class SyncBlockSubscriptionManager {
|
|
20
22
|
private deps;
|
|
23
|
+
private subscriptions;
|
|
24
|
+
private titleSubscriptions;
|
|
21
25
|
private graphqlSubscriptions;
|
|
22
26
|
private subscriptionChangeListeners;
|
|
23
27
|
private useRealTimeSubscriptions;
|
|
28
|
+
private pendingCacheDeletions;
|
|
24
29
|
constructor(deps: SyncBlockSubscriptionManagerDeps);
|
|
30
|
+
/**
|
|
31
|
+
* Returns the subscriptions map. Used by external consumers (e.g. batch fetcher, flush)
|
|
32
|
+
* that need to read the current subscription state.
|
|
33
|
+
*/
|
|
34
|
+
getSubscriptions(): Map<ResourceId, {
|
|
35
|
+
[localId: BlockInstanceId]: SubscriptionCallback;
|
|
36
|
+
}>;
|
|
25
37
|
setRealTimeSubscriptionsEnabled(enabled: boolean): void;
|
|
26
38
|
isRealTimeSubscriptionsEnabled(): boolean;
|
|
27
39
|
getSubscribedResourceIds(): ResourceId[];
|
|
28
40
|
onSubscriptionsChanged(listener: () => void): () => void;
|
|
29
41
|
notifySubscriptionChangeListeners(): void;
|
|
30
42
|
handleSubscriptionUpdate(syncBlockInstance: SyncBlockInstance): void;
|
|
43
|
+
subscribeToSyncBlock(resourceId: string, localId: string, callback: SubscriptionCallback): () => void;
|
|
44
|
+
subscribeToSourceTitle(node: PMNode, callback: TitleSubscriptionCallback): () => void;
|
|
45
|
+
updateSourceTitleSubscriptions(resourceId: string, title: string): void;
|
|
46
|
+
/**
|
|
47
|
+
* Notifies all subscription callbacks for a given resource ID with the provided sync block instance.
|
|
48
|
+
*/
|
|
49
|
+
notifySubscriptionCallbacks(resourceId: ResourceId, syncBlock: SyncBlockInstance): void;
|
|
31
50
|
setupSubscription(resourceId: ResourceId): void;
|
|
32
51
|
cleanupSubscription(resourceId: ResourceId): void;
|
|
33
52
|
setupSubscriptionsForAllBlocks(): void;
|
|
@@ -1,23 +1,15 @@
|
|
|
1
1
|
import { type RendererSyncBlockEventPayload } from '@atlaskit/editor-common/analytics';
|
|
2
2
|
import type { Experience } from '@atlaskit/editor-common/experiences';
|
|
3
|
-
import { ProviderFactory, type MediaProvider } from '@atlaskit/editor-common/provider-factory';
|
|
3
|
+
import { type ProviderFactory, type MediaProvider } from '@atlaskit/editor-common/provider-factory';
|
|
4
4
|
import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
5
5
|
import { type ResourceId, type SyncBlockNode, type SyncBlockPrefetchData } from '../common/types';
|
|
6
6
|
import type { SyncBlockInstance, SubscriptionCallback, SyncBlockDataProviderInterface, TitleSubscriptionCallback, SyncBlockSourceInfo } from '../providers/types';
|
|
7
7
|
export declare class ReferenceSyncBlockStoreManager {
|
|
8
8
|
private dataProvider?;
|
|
9
9
|
private isCacheDirty;
|
|
10
|
-
private subscriptions;
|
|
11
|
-
private titleSubscriptions;
|
|
12
|
-
private providerFactories;
|
|
13
10
|
private fireAnalyticsEvent?;
|
|
14
11
|
private syncBlockFetchDataRequests;
|
|
15
12
|
private syncBlockSourceInfoRequests;
|
|
16
|
-
private isRefreshingSubscriptions;
|
|
17
|
-
private pendingCacheDeletions;
|
|
18
|
-
private graphqlSubscriptions;
|
|
19
|
-
private useRealTimeSubscriptions;
|
|
20
|
-
private subscriptionChangeListeners;
|
|
21
13
|
private newlyAddedSyncBlocks;
|
|
22
14
|
private lastFlushedSyncedBlocks;
|
|
23
15
|
private onUnpublishedSyncBlockDetected?;
|
|
@@ -27,11 +19,9 @@ export declare class ReferenceSyncBlockStoreManager {
|
|
|
27
19
|
fetchExperience: Experience | undefined;
|
|
28
20
|
private fetchSourceInfoExperience;
|
|
29
21
|
private saveExperience;
|
|
30
|
-
private _subscriptionManager
|
|
31
|
-
private _providerFactoryManager
|
|
32
|
-
private _batchFetcher
|
|
33
|
-
private pendingFetchRequests;
|
|
34
|
-
private scheduledBatchFetch;
|
|
22
|
+
private _subscriptionManager;
|
|
23
|
+
private _providerFactoryManager;
|
|
24
|
+
private _batchFetcher;
|
|
35
25
|
constructor(dataProvider?: SyncBlockDataProviderInterface);
|
|
36
26
|
/**
|
|
37
27
|
* Enables or disables real-time GraphQL subscriptions for block updates.
|
|
@@ -55,10 +45,6 @@ export declare class ReferenceSyncBlockStoreManager {
|
|
|
55
45
|
* @returns Unsubscribe function to remove the listener
|
|
56
46
|
*/
|
|
57
47
|
onSubscriptionsChanged(listener: () => void): () => void;
|
|
58
|
-
/**
|
|
59
|
-
* Notifies all subscription change listeners.
|
|
60
|
-
*/
|
|
61
|
-
private notifySubscriptionChangeListeners;
|
|
62
48
|
/**
|
|
63
49
|
* Handles incoming data from a GraphQL subscription.
|
|
64
50
|
* Called by React subscription components when they receive updates.
|
|
@@ -78,35 +64,6 @@ export declare class ReferenceSyncBlockStoreManager {
|
|
|
78
64
|
getInitialSyncBlockData(resourceId: ResourceId): SyncBlockInstance | undefined;
|
|
79
65
|
private updateSessionCache;
|
|
80
66
|
private getFromSessionCache;
|
|
81
|
-
/**
|
|
82
|
-
* Refreshes the subscriptions for all sync blocks.
|
|
83
|
-
* This is a fallback polling mechanism when real-time subscriptions are not enabled.
|
|
84
|
-
* @returns {Promise<void>}
|
|
85
|
-
*/
|
|
86
|
-
refreshSubscriptions(): Promise<void>;
|
|
87
|
-
/**
|
|
88
|
-
* Sets up a GraphQL subscription for a specific block.
|
|
89
|
-
* @param resourceId - The resource ID of the block to subscribe to
|
|
90
|
-
*/
|
|
91
|
-
private setupGraphQLSubscription;
|
|
92
|
-
/**
|
|
93
|
-
* Handles updates received from GraphQL subscriptions.
|
|
94
|
-
* @param syncBlockInstance - The updated sync block instance
|
|
95
|
-
*/
|
|
96
|
-
private handleGraphQLSubscriptionUpdate;
|
|
97
|
-
/**
|
|
98
|
-
* Cleans up the GraphQL subscription for a specific block.
|
|
99
|
-
* @param resourceId - The resource ID of the block to unsubscribe from
|
|
100
|
-
*/
|
|
101
|
-
private cleanupGraphQLSubscription;
|
|
102
|
-
/**
|
|
103
|
-
* Sets up GraphQL subscriptions for all currently subscribed blocks.
|
|
104
|
-
*/
|
|
105
|
-
private setupGraphQLSubscriptionsForAllBlocks;
|
|
106
|
-
/**
|
|
107
|
-
* Cleans up all GraphQL subscriptions.
|
|
108
|
-
*/
|
|
109
|
-
private cleanupAllGraphQLSubscriptions;
|
|
110
67
|
fetchSyncBlockSourceInfoBySourceAri(sourceAri: string, hasAccess?: boolean): Promise<SyncBlockSourceInfo | undefined>;
|
|
111
68
|
fetchSyncBlockSourceInfo(resourceId: ResourceId): Promise<SyncBlockSourceInfo | undefined>;
|
|
112
69
|
/**
|
|
@@ -124,7 +81,6 @@ export declare class ReferenceSyncBlockStoreManager {
|
|
|
124
81
|
private processFetchedData;
|
|
125
82
|
private updateCacheWithSourceInfo;
|
|
126
83
|
private updateCache;
|
|
127
|
-
private updateSourceTitleSubscriptions;
|
|
128
84
|
getFromCache(resourceId: ResourceId): SyncBlockInstance | undefined;
|
|
129
85
|
private deleteFromCache;
|
|
130
86
|
private debouncedBatchedFetchSyncBlocks;
|
|
@@ -142,7 +98,6 @@ export declare class ReferenceSyncBlockStoreManager {
|
|
|
142
98
|
getSSRProviders(resourceId: ResourceId): {
|
|
143
99
|
media: MediaProvider;
|
|
144
100
|
} | null;
|
|
145
|
-
private retrieveDynamicProviders;
|
|
146
101
|
/**
|
|
147
102
|
* Update reference synced blocks on the document with the BE
|
|
148
103
|
*
|
|
@@ -1,33 +1,52 @@
|
|
|
1
1
|
import { type RendererSyncBlockEventPayload } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
3
|
import type { ResourceId, BlockInstanceId } from '../common/types';
|
|
3
|
-
import type { SyncBlockInstance, SubscriptionCallback, SyncBlockDataProviderInterface, SyncBlockSourceInfo } from '../providers/types';
|
|
4
|
+
import type { SyncBlockInstance, SubscriptionCallback, SyncBlockDataProviderInterface, SyncBlockSourceInfo, TitleSubscriptionCallback } from '../providers/types';
|
|
4
5
|
export interface SyncBlockSubscriptionManagerDeps {
|
|
6
|
+
debouncedBatchedFetchSyncBlocks: (resourceId: string) => void;
|
|
7
|
+
deleteFromCache: (resourceId: ResourceId) => void;
|
|
5
8
|
fetchSyncBlockSourceInfo: (resourceId: ResourceId) => Promise<SyncBlockSourceInfo | undefined>;
|
|
6
9
|
getDataProvider: () => SyncBlockDataProviderInterface | undefined;
|
|
7
10
|
getFireAnalyticsEvent: () => ((payload: RendererSyncBlockEventPayload) => void) | undefined;
|
|
8
11
|
getFromCache: (resourceId: ResourceId) => SyncBlockInstance | undefined;
|
|
9
|
-
|
|
10
|
-
[localId: BlockInstanceId]: SubscriptionCallback;
|
|
11
|
-
}>;
|
|
12
|
+
markCacheDirty: () => void;
|
|
12
13
|
updateCache: (syncBlockInstance: SyncBlockInstance) => void;
|
|
13
14
|
}
|
|
14
15
|
/**
|
|
15
16
|
* Manages the lifecycle of GraphQL WebSocket subscriptions for sync block
|
|
16
|
-
* real-time updates,
|
|
17
|
-
*
|
|
17
|
+
* real-time updates, owns the subscriptions and titleSubscriptions maps,
|
|
18
|
+
* and provides a listener API so React components can react when the set
|
|
19
|
+
* of subscribed resource IDs changes.
|
|
18
20
|
*/
|
|
19
21
|
export declare class SyncBlockSubscriptionManager {
|
|
20
22
|
private deps;
|
|
23
|
+
private subscriptions;
|
|
24
|
+
private titleSubscriptions;
|
|
21
25
|
private graphqlSubscriptions;
|
|
22
26
|
private subscriptionChangeListeners;
|
|
23
27
|
private useRealTimeSubscriptions;
|
|
28
|
+
private pendingCacheDeletions;
|
|
24
29
|
constructor(deps: SyncBlockSubscriptionManagerDeps);
|
|
30
|
+
/**
|
|
31
|
+
* Returns the subscriptions map. Used by external consumers (e.g. batch fetcher, flush)
|
|
32
|
+
* that need to read the current subscription state.
|
|
33
|
+
*/
|
|
34
|
+
getSubscriptions(): Map<ResourceId, {
|
|
35
|
+
[localId: BlockInstanceId]: SubscriptionCallback;
|
|
36
|
+
}>;
|
|
25
37
|
setRealTimeSubscriptionsEnabled(enabled: boolean): void;
|
|
26
38
|
isRealTimeSubscriptionsEnabled(): boolean;
|
|
27
39
|
getSubscribedResourceIds(): ResourceId[];
|
|
28
40
|
onSubscriptionsChanged(listener: () => void): () => void;
|
|
29
41
|
notifySubscriptionChangeListeners(): void;
|
|
30
42
|
handleSubscriptionUpdate(syncBlockInstance: SyncBlockInstance): void;
|
|
43
|
+
subscribeToSyncBlock(resourceId: string, localId: string, callback: SubscriptionCallback): () => void;
|
|
44
|
+
subscribeToSourceTitle(node: PMNode, callback: TitleSubscriptionCallback): () => void;
|
|
45
|
+
updateSourceTitleSubscriptions(resourceId: string, title: string): void;
|
|
46
|
+
/**
|
|
47
|
+
* Notifies all subscription callbacks for a given resource ID with the provided sync block instance.
|
|
48
|
+
*/
|
|
49
|
+
notifySubscriptionCallbacks(resourceId: ResourceId, syncBlock: SyncBlockInstance): void;
|
|
31
50
|
setupSubscription(resourceId: ResourceId): void;
|
|
32
51
|
cleanupSubscription(resourceId: ResourceId): void;
|
|
33
52
|
setupSubscriptionsForAllBlocks(): void;
|
package/package.json
CHANGED
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"@atlaskit/editor-prosemirror": "^7.3.0",
|
|
30
30
|
"@atlaskit/node-data-provider": "^9.0.0",
|
|
31
31
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
32
|
-
"@atlaskit/tmp-editor-statsig": "^
|
|
32
|
+
"@atlaskit/tmp-editor-statsig": "^41.0.0",
|
|
33
33
|
"@babel/runtime": "^7.0.0",
|
|
34
34
|
"@compiled/react": "^0.20.0",
|
|
35
35
|
"graphql-ws": "^5.14.2",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"uuid": "^3.1.0"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"@atlaskit/editor-common": "^112.
|
|
41
|
+
"@atlaskit/editor-common": "^112.6.0",
|
|
42
42
|
"react": "^18.2.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
@@ -81,16 +81,12 @@
|
|
|
81
81
|
}
|
|
82
82
|
},
|
|
83
83
|
"name": "@atlaskit/editor-synced-block-provider",
|
|
84
|
-
"version": "4.1.
|
|
84
|
+
"version": "4.1.2",
|
|
85
85
|
"description": "Synced Block Provider for @atlaskit/editor-plugin-synced-block",
|
|
86
86
|
"author": "Atlassian Pty Ltd",
|
|
87
87
|
"license": "Apache-2.0",
|
|
88
88
|
"publishConfig": {
|
|
89
89
|
"registry": "https://registry.npmjs.org/"
|
|
90
90
|
},
|
|
91
|
-
"platform-feature-flags": {
|
|
92
|
-
"platform_synced_block_patch_5": {
|
|
93
|
-
"type": "boolean"
|
|
94
|
-
}
|
|
95
|
-
}
|
|
91
|
+
"platform-feature-flags": {}
|
|
96
92
|
}
|